【发布时间】:2020-11-27 01:14:50
【问题描述】:
我一直在关注Medium 上的一篇文章,在托管 REST API 的 Cloud Run 服务前部署 Cloud Endpoints v1,一切正常。
我现在需要启用 CORS 支持,并且我已将以下配置添加到我的端点 YAML 文件中,但是当我的浏览器尝试发出飞行前请求时出现错误消息“此服务不允许 CORS 流量” (我也用 Postman 测试过同样的错误)。我知道有一个标志可以使用环境变量启用 CORS --cors_preset=basic,但我不确定要设置什么键。任何想法或帮助表示赞赏。
端点 YAML 狙击手:
swagger: '2.0'
info:
title: Cloud Endpoints with Cloud Run
description: Testing Cloud Endpoints with Cloud Run
version: 1.0.0
host: endpoint-<hash>-uc.a.run.app
x-google-endpoints:
- name: endpoint-<hash>-uc.a.run.app
allowCors: true
schemes:
- https
produces:
- application/json
错误:
{
"code": 7,
"message": "The service does not allow CORS traffic.",
"details": [
{
"@type": "type.googleapis.com/google.rpc.DebugInfo",
"stackEntries": [],
"detail": "service_control"
}
]
}
PS:感谢Guillaum Blaquiere 的精彩文章。
更新: 我最终使用不完整的 URL 进行了测试,因此收到了上述错误,因为我的后端服务未配置为响应所有飞行前请求 URL。修复此问题后,我现在仅在 CORS 飞行前配置的 URL 上收到以下错误。
{
"code": 13,
"message": "INTERNAL_SERVER_ERROR",
"details": [
{
"@type": "type.googleapis.com/google.rpc.DebugInfo",
"stackEntries": [
],
"detail": "application"
}
]
}
和日志:
invalid URL prefix in "", client: <CLIENT_IP>, server: , request: "OPTIONS /api/v1/<REMAINING_URL> HTTP/1.1", host: "endpoint-<HASH>-uc.a.run.app"
【问题讨论】:
标签: google-cloud-endpoints google-cloud-run