Closed denes closed 5 years ago
Why not use the cors middleware? https://github.com/expressjs/cors
This might work too but the cors middleware is the generally accepted solution. -response.headers['Access-Control-Allow-Origin'] = ''; +response.setHeader('Access-Control-Allow-Origin', '');
Is not working using cors();
I have try too response.setHeader('Access-Control-Allow-Origin', '*'); but is not working.
The right way to solve this is to use middleware, like
app.use(async (req, res, next) => {
await next();
res.setHeader('Access-Control-Allow-Origin', '*');
});
However, the response transform should let you set a header, I guess, so I fixed it in 1.7.1
@denes did you find a solution?
How I do to works in all project replace headers response:, I try:
module.exports.handler = serverless(app, { response: function (response, event, context) { // Not working response.headers['Access-Control-Allow-Origin'] = '*'; } });
But, if I do for each function it works:
function (req, res) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.status(200).json('OK');
}
Can you help me?