首页 > 解决方案 > android 4.4 上的 Ionic 1 发行版存在 cors 错误

问题描述

在 android 4.4 上使用发布版本时,我目前遇到了 Ionic 1 的问题。我不断收到cors错误消息。此外,我正在使用 node.js 后端cors,其中已经指定了请求。这是到目前为止看到的错误:

SEC7121:[CORS]当凭证模式用于“ https://www.slywolf.co.za/api/auth/signin ”的跨源资源时,在响应标头中找到源“ http://localhost:8100 ” '。*Access-Control-Allow-Origininclude

任何有关这方面的帮助将不胜感激。

标签: node.jsionic-frameworkcors

解决方案


在你的 node.js 服务器中添加这个作为中间件。
这将允许使用凭据的跨源请求

app.use(function(req, res, next) {
        res.header("Access-Control-Allow-Origin", "http://localhost:8100");
        res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
        res.header("Access-Control-Allow-Methods", "GET, POST,PATCH, DELETE, PUT");
         res.header("Access-Control-Allow-Credentials", true);
        next();
    });

推荐阅读