簡體   English   中英

node.js 中的 CORS 問題失敗

[英]CORS issue in node.js failing

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();
});

我使用郵遞員一切正常,但是在測試我在http://localhost:8100 上運行的 ionic 應用程序時遇到了 CORS 問題。 我用谷歌搜索並設法找到上面設置的標題解決方案,但現在我收到此錯誤:

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

任何想法?

嘗試使用 cors 中間件。

var cors = require('cors');

app.use(cors());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM