Google App Engine CORS“解析 ./app.yaml 时出错:未知 url 处理程序类型" [英] Google App Engine CORS “Error parsing ./app.yaml: Unknown url handler type”

查看:61
本文介绍了Google App Engine CORS“解析 ./app.yaml 时出错:未知 url 处理程序类型"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to apply CORS to one of my app engines, but I'm encountering an error. I've tried looking at the recommendations for other answers (spacing) but it still errors:

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 设置

nodejs cors settings

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
}))

推荐答案

您只能为静态文件设置 HTTP 标头.你需要在 nodejs 代码中做 CORS 部分.

You can only set HTTP headers for static files. You need to do the CORS part in nodejs code.

这篇关于Google App Engine CORS“解析 ./app.yaml 时出错:未知 url 处理程序类型"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆