google-cloud-platform - Google Cloud 在 CORS 中功能多个域

标签 google-cloud-platform google-cloud-functions

如何在 CORS 中启用多个选择域?我可以看到here如何启用 CORS,但它是一个 * 卡或只是一个域。

我尝试了类似下面的方法,但没有成功

if request.method == 'OPTIONS':
        # Allows GET requests from any origin with the Content-Type
        # header and caches preflight response for an 3600s
        # TODO: Restrict Origin
        headers = {
            'Access-Control-Allow-Origin': 'http://localhost:4200, http://localhost:8080',
            'Access-Control-Allow-Methods': 'POST',
            'Access-Control-Allow-Headers': 'Content-Type',
            'Access-Control-Max-Age': '3600'
        }

        return ('', 204, headers)

    # Set CORS headers for the main request
    headers = {
        'Access-Control-Allow-Origin': 'http://localhost:4200, http://localhost:8080'
    }
    return ('', 204, headers)

最佳答案

您无法设置多个 Access-Control-Allow-Origin 值:您可以获取一个名为 origin 的值或 * ( docs )。

在这种情况下,您可能只需返回http://localhost;否则,我建议您创建允许的来源列表,检查传入请求的 Origin header ,并返回正确的 header 。

关于google-cloud-platform - Google Cloud 在 CORS 中功能多个域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54827798/

相关文章:

Kubernetes Pod 在 "Pod sandbox changed, it will be killed and re-created"上失败

Firebase 模拟器云功能仅适用于 Flutter 中的默认 us-central1 位置

python - 我需要帮助调试 Pub/Sub Google Cloud Functions

javascript - 如何在Firebase存储触发功能中获取公共(public)下载链接: "onFinalize"?

Firebase 存储不会启用 CORS

node.js - 使用 Node.js 的多个 Firebase 通知

google-cloud-functions - 是否可以在 Firestore Cloud Function 中获取所有文档?

ruby-on-rails - 如何从部署在 k8s 中的 Rails 应用程序向 Google Cloud 进行身份验证

firebase - 如何在 Cloud Firestore 中保存来自 Cloud Function 的文档引用?

google-app-engine - AppEngine App Deploy 给出 "Failed to copy file."