electron跨域设置

electron 文章 2020-02-01 11:54 2620 0 全屏看文

AI助手支持GPT4.0

 app.all("*", function(req, res, next) {
        if (req.path !== "/" && !req.path.includes(".")) {
            res.header("Access-Control-Allow-Credentials", true);
            // 这里获取 origin 请求头 而不是用 *
            res.header("Access-Control-Allow-Origin", req.headers["origin"] || "*");
            res.header("Access-Control-Allow-Headers", "X-Requested-With");
            res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
            res.header("Content-Type", "application/json;charset=utf-8");
        }
        next();
    });


-EOF-

AI助手支持GPT4.0