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

后端 未结 9 2531
借酒劲吻你
借酒劲吻你 2020-11-22 01:54

I have a setup involving

Frontend server (Node.js, domain: localhost:3000) <---> Backend (Django, Ajax, domain: localhost:8000)

Browser <-- webapp <

9条回答
  •  臣服心动
    2020-11-22 02:59

    This works for me in development but I can't advise that in production, it's just a different way of getting the job done that hasn't been mentioned yet but probably not the best. Anyway here goes:

    You can get the origin from the request, then use that in the response header. Here's how it looks in express:

    app.use(function(req, res, next) {
      res.header('Access-Control-Allow-Origin', req.header('origin') );
      next();
    });
    

    I don't know what that would look like with your python setup but that should be easy to translate.

提交回复
热议问题