CORS 工作正常但突然停止工作?

CORS was working fine but suddenly stopped working?

这是我在 Node 中拥有的:

app.use(function (req, res, next) {

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

    // Request methods you wish to allow
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');

    // Request headers you wish to allow
    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');

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

我的 front-end 在 Angular。一切正常,但突然间我开始收到 CORS 错误。当我检查控制台时,我得到这个:

Initiator Context 和 Allowed Origin 完全相同。而且,正如我之前提到的,我遇到了 0 个问题,直到它突然决定停止工作。所以我不明白这里发生了什么。任何帮助将不胜感激。

您可以尝试使用 http://localhost:4200,而不是最后一个 '/'