小编Sho*_*rin的帖子

快速节点服务器的 Firefox CORS 失败

我将 Express.js 与 CORS 中间件一起使用。我在 Firefox v73.0.1(64 位)上出现了非常奇怪的行为

清理 firefox 配置文件...所以没有缓存。

  1. 我尝试直接请求http://localhost/search?q=AMZN,我得到了预期的结果。
  2. 我打开在 localhost:3000 上运行的 web 应用程序。所有这些请求都没有使用 TLS/SSL。
  3. 我收到“跨源请求被阻止:同源策略不允许在http://localhost/search?q=AMZN读取远程资源。(原因:CORS 请求没有成功)。” 当它尝试访问 API 服务器后端时。
  4. 我刷新了直接访问 localhost 的另一个选项卡(之前成功的请求相同),然后我得到了“连接重置”。

Chrome 不会这样做...

我一直在看wireshark,Firefox 只是发送一个GET 请求(其中几个?为什么??我只做一个),发送标头等,然后是连接重置。

听起来像节点做错了什么?或者我不知道。

const express = require('express');
const fetch = require('node-fetch');
const util = require('util');
const app = express();
const port = 80;

var cors = require('cors')

var copts = {
  origin: function (origin, callback) {
      console.log('yeah');
    // allow all
    callback(null, true);
  }
}

const SEARCH_URL = …
Run Code Online (Sandbox Code Playgroud)

firefox node.js cors express

3
推荐指数
1
解决办法
1008
查看次数

标签 统计

cors ×1

express ×1

firefox ×1

node.js ×1