AngularJS performs an OPTIONS HTTP request for a cross-origin resource

OPTIONS request are by no means an AngularJS bug, this is how Cross-Origin Resource Sharing standard mandates browsers to behave. Please refer to this document: https://developer.mozilla.org/en-US/docs/HTTP_access_control, where in the “Overview” section it says: The Cross-Origin Resource Sharing standard works by adding new HTTP headers that allow servers to describe the set of origins that are … Read more

No ‘Access-Control-Allow-Origin’ – Node / Apache Port Issue

Try adding the following middleware to your NodeJS/Express app (I have added some comments for your convenience): // Add headers before the routes are defined app.use(function (req, res, next) { // Website you wish to allow to connect res.setHeader(‘Access-Control-Allow-Origin’, ‘http://localhost:8888’); // Request methods you wish to allow res.setHeader(‘Access-Control-Allow-Methods’, ‘GET, POST, OPTIONS, PUT, PATCH, DELETE’); // … Read more

How to handle CORS using JAX-RS with Jersey

Note: Make sure to read the UPDATE at the bottom. The original answer includes a “lazy” implementation of the CORS filter With Jersey, to handle CORS, you can just use a ContainerResponseFilter. The ContainerResponseFilter for Jersey 1.x and 2.x are a bit different. Since you haven’t mentioned which version you’re using, I’ll post both. Make … Read more

Trying to use fetch and pass in mode: no-cors

mode: ‘no-cors’ won’t magically make things work. In fact it makes things worse, because one effect it has is to tell browsers, “Block my frontend JavaScript code from seeing contents of the response body and headers under all circumstances.” Of course you never want that. What happens with cross-origin requests from frontend JavaScript is that … Read more

CORS: Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true

This is a part of security, you cannot do that. If you want to allow credentials then your Access-Control-Allow-Origin must not use *. You will have to specify the exact protocol + domain + port. For reference see these questions : Access-Control-Allow-Origin wildcard subdomains, ports and protocols Cross Origin Resource Sharing with Credentials Besides * … Read more

How to get a cross-origin resource sharing (CORS) post request working

I finally stumbled upon this link “A CORS POST request works from plain javascript, but why not with jQuery?” that notes that jQuery 1.5.1 adds the Access-Control-Request-Headers: x-requested-with header to all CORS requests. jQuery 1.5.2 does not do this. Also, according to the same question, setting a server response header of Access-Control-Allow-Headers: * does not … Read more

Why is an OPTIONS request sent and can I disable it?

edit 2018-09-13: added some precisions about this pre-flight request and how to avoid it at the end of this reponse. OPTIONS requests are what we call pre-flight requests in Cross-origin resource sharing (CORS). They are necessary when you’re making requests across different origins in specific situations. This pre-flight request is made by some browsers as … Read more