美文网首页NodeJS
CORS on ExpressJS

CORS on ExpressJS

作者: thebestofrocky | 来源:发表于2018-07-25 09:47 被阅读32次

    CORS on ExpressJS

    In your ExpressJS app on node.js, do the following with your routes:

    app.use(function(req, res, next) {
      res.header("Access-Control-Allow-Origin", "*");
      res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
      next();
    });
    
    app.get('/', function(req, res, next) {
      // Handle the get for this route
    });
    
    app.post('/', function(req, res, next) {
     // Handle the post for this route
    });
    

    相关文章

      网友评论

        本文标题:CORS on ExpressJS

        本文链接:https://www.haomeiwen.com/subject/wxoumftx.html