【问题标题】:Google App Engine CORS “Error parsing ./app.yaml: Unknown url handler type”Google App Engine CORS“解析 ./app.yaml 时出错:未知 url 处理程序类型”
【发布时间】:2019-10-18 06:10:41
【问题描述】:

我正在尝试将 CORS 应用于我的一个应用引擎,但遇到了错误。我已经尝试查看其他答案(间距)的建议,但仍然出现错误:

app.yaml

runtime: nodejs10

env_variables:
  NODE_ENV: production
  CLOUD_SQL_CONNECTION_NAME: domain-name-server:australia-southeast1:db_name

handlers:  
- url: /.*
  http_headers:
    Access-Control-Allow-Origin: https://domain_name-fixed.appspot.com/

错误

ERROR: (gcloud.app.deploy) An error occurred while parsing file: [/home/project/domain_name-server/app.yaml]
Unknown url handler type.
<URLMap
    secure=default
    static_files=None
    application_readable=None
    auth_fail_action=redirect
    require_matching_file=None
    static_dir=None
    redirect_http_response_code=None
    http_headers={u'Access-Control-Allow-Origin': 'https://domain_name-fixed.appspot.com/'}
    url=/.*
    script=None
    upload=None
    api_endpoint=None
    expiration=None
    position=None
    login=optional
    mime_type=None
    >
  in "/home/project/domain_name-server/app.yaml", line 10, column 73

nodejs cors 设置

let cors = require("cors")

let origin =
    [
        "http://localhost:8080",
        `http://${ip.address()}:8080`,
        "http://localhost:4000",
        `http://${ip.address()}:4000`,
        "https://domain_name-fixed.appspot.com/"
    ]

app.use(cors({
    origin,
    credentials: true
}))

【问题讨论】:

    标签: javascript node.js google-app-engine yaml


    【解决方案1】:

    您只能为静态文件设置 HTTP 标头。您需要在 nodejs 代码中执行 CORS 部分。

    【讨论】:

    • 啊,不知道。我更新了我的问题以包括 cors 设置。也许我需要使用 ip 而不是它的 url 地址?
    • 从上述处理程序中删除 http_headershttp_headers 只能用于static_filesstatic_dir。并且取决于环境,您可能需要使用 ip 或域。或*.
    猜你喜欢
    • 2023-03-11
    • 2016-04-04
    • 1970-01-01
    • 2017-02-02
    • 2020-03-19
    • 2016-06-13
    • 1970-01-01
    • 2018-04-24
    • 2019-09-17
    相关资源
    最近更新 更多