var cors = require("cors");
cors({ origin: '*' });
cors({ allowHeaders: 'X-PINGOTHER'});
cors({ methods: 'GET,HEAD,PUT,PATCH,POST,DELETE'});
exports.endpoint = function(request, response) {
let text = '100,000';
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.end(text);
}
I am running this on Runkit and still get the error when checking on a website, where I want to display this return value: "No 'Access-Control-Allow-Origin' header is present on the requested resource"
In your example you've loaded the
corsmodule and configured it, but not actually done anything to get it to intercept the HTTP request and send back your CORS headers.If you're just using a simple Runkit endpoint, you don't need the CORS module at all – just add the headers in your endpoint, where you're already adding the
Content-Typeheader: