【发布时间】:2018-06-13 09:33:44
【问题描述】:
我花了数周时间在 Google App Engine 中部署和访问一个示例 Angular 应用程序,但到目前为止它总是失败。
我真的怀疑这与我的 app.yaml 文件的处理程序配置有关。我有一个 bitbucket 配置,使用它我将所有文件(webpack)打包到 dist 文件夹中,移动到该文件夹中,然后我才执行命令 gcloud app deploy
这是我的管道脚本
image: python:3.5.1
pipelines:
custom:
default:
- step:
script:
- curl -sL https://deb.nodesource.com/setup_10.x | bash
- apt-get install -y nodejs
- apt-get install -y build-essential
- npm install -g @angular/cli@latest
- npm install
#setting the base href to see if it works when deployed
- ng build --prod --aot
# by default AOT compiler is taken
- cp app.yaml dist
- curl -o /tmp/google-cloud-sdk.tar.gz https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-200.0.0-linux-x86_64.tar.gz
- tar -xvf /tmp/google-cloud-sdk.tar.gz -C /tmp/
- /tmp/google-cloud-sdk/install.sh -q
- source /tmp/google-cloud-sdk/path.bash.inc
- echo $GCLOUD_API_KEYFILE | base64 --decode --ignore-garbage > ./gcloud-api-key.json
- gcloud config set project $GCLOUD_PROJECT
- gcloud auth activate-service-account --key-file gcloud-api-key.json
- echo $GCLOUD_API_KEYFILE > /tmp/client-secret.json
#setting it before updating the config
- gcloud config set project $GCLOUD_PROJECT
- gcloud config set gcloudignore/enabled false
- gcloud app deploy app.yaml --verbosity=info
这是我的 app.yaml 文件
runtime: python27
api_version: 1
env: standard
threadsafe: true
service: sampleapp
handlers:
# Routing for bundles to serve directly
- url: /((?:inline|main|polyfills|styles|runtime|vendor)\.[a-z0-9]+\.js)
secure: always
redirect_http_response_code: 301
static_files: /\1
upload:/.*
# Routing for a prod styles.bundle.css to serve directly
- url: /(styles\.[a-z0-9]+\.css)
secure: always
redirect_http_response_code: 301
static_files:/\1
upload:/.*
# Routing for typedoc, assets and favicon.ico to serve directly
- url: /((?:assets|docs)/.*|favicon\.ico)
secure: always
redirect_http_response_code: 301
static_files: dist/\1
upload: dist/.*
# Any other requests are routed to index.html for angular to handle
so we don't need hash URLs
- url: /.*
secure: always
redirect_http_response_code: 301
static_files:/index.html
upload:/index.html
http_headers:
Strict-Transport-Security: max-age=31536000;
includeSubDomains
X-Frame-Options: DENY
我认为设置处理程序部分可能有误。那么请告诉我我的处理程序部分是否正确?
编辑
当我部署应用程序时,它会成功部署,当我在 GAE 中调试版本时,我可以看到 js 文件、/static 文件夹和 index.html 文件。
但是,当我尝试访问 URL 时,我总是收到 404 NOT FOUND 错误,或者没有下载任何 js 文件(bundle.#hashnumber.bundle.js、main.#hashnumber.bundle.js、vendor.#hasnnumber.bundle.js)。
我也尝试在本地运行devserver:
dev_appserver.py app.yaml --port 8081
INFO 2018-06-15 05:28:52,963 devappserver2.py:120] Skipping SDK update check.
INFO 2018-06-15 05:28:53,214 admin_server.py:152] Starting admin server at: localhost:8000
INFO 2018-06-15 05:28:53,458 devappserver2.py:215] No default module found. Ignoring. New instance for module "testapp" serving on: localhost:8081
INFO 2018-06-15 05:28:54,711 module.py:846] testapp: "GET /_ah/start HTTP/1.1" 404 -
我浏览了他们的文档,但从未完全理解如何为/_ah/start 实现处理程序以不返回任何内容
【问题讨论】:
-
您的缩进在 app.yaml 中搞砸了。每个
- url应该从该行的第一个字符开始。 -
你应该也包括
gcloud app deploy产生的日志 -
@DanCornilescu - 问题是 Dan 在我部署它时,它已成功部署,当我调试版本时,我能够看到该服务器中的所有 js/static 文件夹/和 index.html在 GAE 中,但是当我尝试访问 URL 或没有任何 js 文件(bundle.#hashnumber.bundle.js、main.#hashnumber.bundle.js、vendor.#hasnnumber. bundle.js) 正在下载
-
@JeffO'Neill - 我在这里弄乱了缩进,但在实际文件中没有。我现在已经编辑了缩进:)
-
@Joey587 - 请编辑您的帖子并将详细信息放入其中 - 作为 cmets,它们真的很难阅读。是的,确切的请求路径及其结果是很好的细节 - 甚至可能是相应的应用程序日志。
标签: angular google-app-engine angular5 gcloud