question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OPTIONS sent before POST in the browser for CORS request

See original GitHub issue

Hi, 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:

  1. Can sending OPTIONS before POST (in browser env) be disabled in superagent somehow?
  2. 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:closed
  • Created 9 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
defunctzombiecommented, Nov 27, 2014

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

0reactions
fiatjafcommented, Jun 25, 2015

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found