I'm not able to correctly handle CORS issues when doing either PATCH
/POST
/PUT
requests from the browser sending an Authorization
header with a Bearer token
(this works correctly outside of the browser and for GET
requests) in Zeit Now serverless.
I'm using Auth0 for the authorization side if that helps.
This is my now.json
headers section, I've tried a lot of combinations for these, but neither succeeded from the browser.
- I tried using npm
cors
package without success - Tried to add
routes
innow.json
- Tried setting headers at the top of the serverless function using
res.addHeader()
- Also tried handling
OPTIONS
request manually doing variations of this:
Finally, this is the error that I get
Access to XMLHttpRequest at 'https://api.example.org/api/users' from origin 'https://example.org' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
Not sure what I'm wrong or how to handle this properly.
Need an example? follow [this](https://dzone.com/articles/cors-in-node) – HeptaDecane Sep 10 '21 at 22:00