我有一个app.yaml文件,其中包含一堆不同的静态文件指令,例如
- url: /sitemap.xml
static_files: public/sitemap.xml
secure: always
upload: public/sitemap.xml
http_headers:
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Referrer-Policy: no-referrer
Feature-Policy: microphone 'none'; notifications 'none'
Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' ; font-src fonts.gstatic.com ; style-src 'self' 'unsafe-inline' fonts.googleapis.com现在,我真的不想为我提供的每个静态文件或路径添加数十个http头的副本,从而使app.yaml文件变得臃肿。是否可以指定一个全局标头指令,用于所有提供服务的静态路径?
提前感谢!
发布于 2020-07-15 03:39:16
GAE不允许在app.yaml中使用锚点。否则,您可以执行以下操作:
runtime: python37
entrypoint: gunicorn -b :$PORT application:app --timeout 36000
headers: &headers
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Referrer-Policy: no-referrer
Feature-Policy: microphone 'none'; notifications 'none'
Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' ; font-src fonts.gstatic.com ; style-src 'self' 'unsafe-inline' fonts.googleapis.com
handlers:
- url: /sitemap.xml
static_files: public/sitemap.xml
secure: always
upload: public/sitemap.xml
http_headers: *headers如果您使用Admin API (https://cloud.google.com/appengine/docs/admin-api/deploying-overview)进行部署,您可以使用上面的app.yaml,但将其转换为app.json (例如https://www.convertjson.com/yaml-to-json.htm),这会将上面带有锚点的yaml代码转换为更长的版本:
{
"runtime": "python37",
"entrypoint": "gunicorn -b :$PORT application:app --timeout 36000",
"headers": {
"Strict-Transport-Security": "max-age=31536000; includeSubDomains",
"X-Frame-Options": "SAMEORIGIN",
"X-Content-Type-Options": "nosniff",
"Referrer-Policy": "no-referrer",
"Feature-Policy": "microphone 'none'; notifications 'none'",
"Content-Security-Policy": "default-src 'self'; script-src 'self' 'unsafe-inline' ; font-src fonts.gstatic.com ; style-src 'self' 'unsafe-inline' fonts.googleapis.com"
},
"handlers": [
{
"url": "/sitemap.xml",
"static_files": "public/sitemap.xml",
"secure": "always",
"upload": "public/sitemap.xml",
"http_headers": {
"Strict-Transport-Security": "max-age=31536000; includeSubDomains",
"X-Frame-Options": "SAMEORIGIN",
"X-Content-Type-Options": "nosniff",
"Referrer-Policy": "no-referrer",
"Feature-Policy": "microphone 'none'; notifications 'none'",
"Content-Security-Policy": "default-src 'self'; script-src 'self' 'unsafe-inline' ; font-src fonts.gstatic.com ; style-src 'self' 'unsafe-inline' fonts.googleapis.com"
}
}
]
}可能不是你所希望的,而是把它放在那里。
https://stackoverflow.com/questions/62899656
复制相似问题