-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to use InfluxDB 1.8 directly from the browser #199
Comments
@cailloumajor the browser example works fine when used against a proxy and it does not when using CORS. The v1 server code does not handle CORS as v2 does, so it is blocked by the client. I am on the way to find a workaround. |
I found out that CORS is not supported in "v2 compatibility endpoints" of InfluxDB v1, this is now reported in influxdata/influxdb#18391 . Using a proxy that would satisfy CORS requirements or running a browser to ignore CORS requirements is a workaround. I am now looking deeper at your workaround @cailloumajor |
Regarding your workaround @cailloumajor . The "no-cors" mode allows only limited settings of content-type, "application/json" is not allowed ... that's why your FF sends text/plain. Additionally, in the 'no-cors' mode, fetch returns an opaque response so the code cannot see response headers and even body. |
@sranka thank you for those informations, and sorry for wrongly focusing on headers names case. I am going to try using a proxy in my project, it was planned for production but it seems I need it in development too... |
You are welcome @cailloumajor , The actual issue is influxdata/influxdb#18391. |
@sranka : i am also facing the CORS issue when i use the example code in my browser. // https://v2.docs.influxdata.com/v2.0/reference/syntax/annotated-csv/
|
Thank you @jitendracodehacker for letting us know, it depends on whether your InfluxDB contains a fix for influxdata/influxdb#18391 , AFAIK there is no public 1.8 release with this fix yet. The client example uses a proxy to workaround 1.8 CORS issues. |
It should be fine if your angular app is served from the same server where the proxy is running, no CORS is then used. You can also add cors to the proxy server, so that the proxy can be accessed from any origin. |
Background
I am developing a web application based on Vue.js (client-side) that needs to query InfluxDB 1.8 at regular interval, using Flux. The application reaches InfluxDB directly by
http://host:port
. I first tried to use this library (version1.4.0-nightly.14
) as in examples/influxdb-1.8.ts, but I couldn't make it work due to CORS preflight not acknowledged by InfluxDB (v1.8.0).I then decided to use
@influxdata/influxdb-client-apis
(version1.3.0
) to do the query (usingQueryAPI.postQuery
), with the code below:(note the usage of
{ mode: "no-cors" }
aspostQuery
's request options, intended forfetch
call, and which raises a typing error)The query now fulfills, but I receive an disappointing
undefined
string as the result of the succeeding Promise ! (see below the console of Firefox Developer Edition)The response from InfluxDB seems to be conform:
Description of the problem
For a reason I don't understand, commit d106c08 made
Content-Type
header name all-lowercase (and I fear other cases like this were introduced later, eg.accept-encoding
1c9ba45), IMHO preventing them to being correctly interpreted by browsers and InfluxDB (see below, showing thatContent-Type: application/json
is not sent to InfluxDB, despite the intention inQueryAPI.postQuery
).For the case described in this issue, this makes
responseContentType
below always equal to empty string, making the whole function returnundefined
.influxdb-client-js/packages/core/src/impl/browser/FetchTransport.ts
Lines 110 to 135 in 3fd9068
Additional thoughts
This issue makes me being in trouble, because it prevents the whole library from being usable in my use case, this one not being an edge case IMHO.
Does anyone have an idea about the CORS preflight problem described at the beginning ?
The text was updated successfully, but these errors were encountered: