You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node.js中CORS跨域报错求助:配置及扩展均无效

问题:Chrome前端页面控制台持续弹出CORS及404错误

在Chrome浏览器打开前端页面时,控制台持续弹出以下两个错误:

Access to XMLHttpRequest at 'https://hog.simplify.jobs/decide/?v=3&ip=1&_=1688782636903&ver=1.57.2' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

POST https://hog.simplify.jobs/decide/?v=3&ip=1&_=1688782636903&ver=1.57.2 net::ERR_FAILED 404 contentScript.bundle.js:1 

已尝试以下方案,但均未解决问题:

  • 安装Chrome跨域扩展,无效
  • 在Node.js后端配置CORS,两种方式都试过:
    1. 使用cors库:
      app.use(cors({origin: '*'}));
      
    2. 手动设置响应头:
      app.use(function (req, res, next) {
          res.setHeader('Access-Control-Allow-Origin', '*');
          res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
          res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With, content-type');
          res.setHeader('Access-Control-Allow-Credentials', true);
          next();
      });
      

内容的提问来源于stack exchange,提问作者Freedom Trail

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 19:27:03