小编Sar*_*aaz的帖子

如何在 nodejs express 重定向上启用 CORS?

我在后端使用 nodejs express 作为我的 API。我想知道如何在redirect方法上启用 CORS 。

以下是我的快速重定向代码:

res.redirect(redirectUrl);
Run Code Online (Sandbox Code Playgroud)

当客户端向上述 API 发送请求时,它会将请求重定向到 as3但我收到以下错误:

Access to XMLHttpRequest at 'https://s3-ap-southeast-
2.amazonaws.com/index.html' (redirected from 
'http://localhost:9090/v0/api') from origin 'http://localhost:9090' has 
been blocked by CORS policy: Response to preflight request doesn't pass 
access control check: No 'Access-Control-Allow-Origin' header is present on
 the requested resource.
Run Code Online (Sandbox Code Playgroud)

前端正在运行,http://localhost:9090并且前端域已添加到 s3 存储桶中的 CORS 上。如果我https://s3-ap-southeast-2.amazonaws.com/index.html直接从浏览器发送请求,它工作正常。所以我认为问题出在nodejs express redirect方法上。如何为重定向启用 CORS?

我知道如何启用,CORS但我的问题与redirect. 我怎样才能使重定向工作?

amazon-s3 node.js cors express

5
推荐指数
1
解决办法
5050
查看次数

标签 统计

amazon-s3 ×1

cors ×1

express ×1

node.js ×1