【发布时间】:2019-05-15 08:43:18
【问题描述】:
我在后端使用 nodejs express 作为我的 API。我想知道如何在 redirect 方法上启用 CORS。
以下是我的快速重定向代码:
res.redirect(redirectUrl);
当客户端向上述 API 发送请求时,它会将请求重定向到 s3,但出现以下错误:
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.
前端在http://localhost:9090 下运行,并且前端域已添加到 s3 存储桶中的 CORS 上。如果我直接从浏览器向https://s3-ap-southeast-2.amazonaws.com/index.html 发送请求,它工作正常。所以我认为问题出在nodejs express redirect 方法上。如何为重定向启用 CORS?
我知道如何启用CORS,但我的问题与redirect 有关。如何使重定向起作用?
【问题讨论】:
-
How to allow CORS?的可能重复
-
这是不同的,因为我的问题是关于重定向而不是直接连接
标签: node.js express amazon-s3 cors