OPTIONS sent before POST in the browser for CORS request
See original GitHub issueHi,
great superagent
!
I use the lib to make requests to HP’s IDOL API. Works great in nodejs but in the browser(build with browserify) it sends an OPTIONS request first before the POST request the app is actually making. This sadly breaks everything because the API throws some error and can’t handle OPTIONS request at all.
the endpoint in question is:
https://api.idolondemand.com/1/job
anyway send an OPTIONS request and one see the Error.
The questions:
- Can sending OPTIONS before POST (in browser env) be disabled in
superagent
somehow? - Is this related to CORS, I mean if the request was not CORS would the browser send OPTIONS before POST at all?
Looks like this “issue” is related to #451 because after the failing OPTIONS request the error is the same.
Issue Analytics
- State:
- Created 9 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
What is the reason behind using OPTION request before ...
The browser sees CORS is not enabled and ignores the response but by that point it's too late - the POST request has...
Read more >Preflight request - MDN Web Docs Glossary: Definitions of ...
A CORS preflight request is a CORS request that checks to see if the CORS protocol is understood and a server is aware...
Read more >Why Is an OPTIONS Request Sent? - Baeldung
Using the request the browser checks with the server whether the request is allowed. Only if the request is allowed, it'll actually perform...
Read more >BROWSER SENDS PRE-FLIGHT OPTION REQUEST ...
The OPTIONS request is so called pre-flight request, which is part of Cross-origin resource sharing (CORS). Browsers use it to check if a ......
Read more >Why is my browser sending an OPTIONS HTTP request ...
As you can see, the POST method is never sent and only a method called OPTIONS is sent to the endpoint. The response...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You cannot. If the browser decides to prelight a request you have no choice. The only way your request won’t be preflighted is if it is considered a “Simple” request. See here for simple requests:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
For anyone with this problem, here’s a fork that does not add
application/json
unless you ask for it: https://github.com/fiatjaf/superagent-cors