Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The CORS error "No 'Access-Control-Allow-Origin'" means that the server (in this case, a GAE Node.js server) is not sending the necessary headers to allow cross-origin requests from a certain domain. The error occurs when a client-side JavaScript application running on a different domain tries to make a request to the server using XMLHttpRequest or fetch(), and the server doesn't explicitly allow requests from that domain.

To fix this error, you need to add the "Access-Control-Allow-Origin" header to the response sent from the server, and set it to either "*" (allow requests from any domain) or the specific domain that's making the request. Here's an example of adding the header in Node.js:

app.use(function(req, res, next) {
  res.setHeader("Access-Control-Allow-Origin", "*");
  res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, PATCH, DELETE");
  res.setHeader("Access-Control-Allow-Headers", "X-Requested-With,content-type");
  next();
});

Note that this code adds additional headers to also allow other HTTP verbs and headers to be used in the request. You might need to adjust these values based on your specific use case.