我将使用 Express 制作的 API 与 API Gateway 封装在一起。 我正在使用 Cognito Userpool 来验证 API Gateway。
当我使用 Angular2 http 服务访问该 API 时,返回了正常值。 但是,当身份验证失败时,会出现以下错误。
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 401.
我正确设置了 header 映射,但这次出现此错误。
当我使用 Postman 访问它时,我得到以下结果。
{
"message": "Unauthorized"
}
当使用 Angular2 访问时,我也希望得到相同的结果。
这可能吗?
最佳答案
遗憾的是,在某些错误情况下(例如 401/403),即使配置正确,API Gateway 也不会返回 CORS header 。
我们意识到这对客户来说是一个痛点,并且正在研究解决方案,但无法 promise 何时可用。
关于javascript - 认知 + API 网关。获取状态 401,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43113729/