【问题标题】:CORS issue in node.js failingnode.js 中的 CORS 问题失败
【发布时间】:2016-06-27 11:16:06
【问题描述】:
app.use(function (req, res, next) {

    // Website you wish to allow to connect
    res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8100');

    // Request headers you wish to allow
    res.setHeader('Access-Control-Allow-Headers', '*');

    // Set to true if you need the website to include cookies in the requests sent
    // to the API (e.g. in case you use sessions)
    res.setHeader('Access-Control-Allow-Credentials', true);

    // Pass to next layer of middleware
    next();
});

我使用邮递员一切正常,但在测试我的 ionic 应用程序时遇到了 CORS 问题,该应用程序在 http://localhost:8100 运行。我用谷歌搜索并设法找到上面设置的标题解决方案,但现在我收到了这个错误:

Request header field owner is not allowed by Access-Control-Allow-Headers in preflight response.

有什么想法吗?

【问题讨论】:

标签: javascript node.js cors cross-domain


【解决方案1】:

尝试使用 cors 中间件。

var cors = require('cors');

app.use(cors());

【讨论】:

    猜你喜欢
    • 2016-04-15
    • 2021-09-04
    • 2015-03-10
    • 2015-10-04
    • 2020-10-21
    • 2018-08-03
    • 2015-10-30
    • 2021-02-02
    • 1970-01-01
    相关资源
    最近更新 更多