Sails.js 预检响应中的 Access-Control-Allow-Headers 不允许请求 header 字段授权

Sails.js Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response

我正在使用 sails.js 和 reactjs 创建单页应用程序,并使用 JWT 作为受保护请求的身份验证。在登录过程中,登录请求按预期工作并能够成功登录。之后,当我尝试使用不记名令牌请求其他请求时,浏览器显示以下错误消息。

Access to XMLHttpRequest at 'http://localhost:1337/monitoringurl' from origin >'http://localhost:3000' has been blocked by CORS policy: Request header field >authorization is not allowed by Access-Control-Allow-Headers in preflight >response.

下面是我在 sails 中的 cors 设置 config/security.js:

cors: { allRoutes: true, allowOrigins: ["http://localhost:3000"], allowCredentials: true, }

我找到了我自己问题的答案。我不得不改变 config/security.js 如下:

cors: { allRoutes: true, allowOrigins: ["http://localhost:3000"], allowCredentials: true, allowRequestHeaders: "content-type, authorization" }