enabling cors on a nginx server in ElasticBeanstalk?

核能气质少年 提交于 2019-12-04 18:08:29

If you set CORS headers in the response that goes out of your node/express application, you don't need to add anything to Nginx configuration.

Below is the configuration that worked for me, also running node.js on Beanstalk, and a cloudfront-hosted client application calling the API.

Modify as needed:

server.use(function(req, res, next) {
  res.header('Access-Control-Allow-Origin', '*')
  res.header('Access-Control-Allow-Credentials', true)
  res.header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')
  res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
  next()
})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!