我正在尝试将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核心设置
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
}))
答案 0 :(得分:2)
您只能为静态文件设置HTTP标头。您需要在nodejs代码中执行CORS部分。