【问题标题】:App Engine app.yaml variable subdirectoriesApp Engine app.yaml 变量子目录
【发布时间】:2021-08-15 18:43:49
【问题描述】:

这是我当前的 app.yaml:

runtime: nodejs10
service: default

instance_class: F1
automatic_scaling:
  min_instances: 0
  max_instances: 2

handlers:

  # Serve extension from where they were requested
- url: /(.*\.(css|ico|js|png|jpg|gif|mp4|txt|xml|json))$
  static_files: dist/apps/my-app/browser/\1
  upload: dist/apps/my-app/browser/.*\.(css|ico|js|png|jpg|gif|mp4|txt|xml|json)$
  secure: always
  expiration: "365d"

  # Handle blog SEO routes
- url: /blog
  static_files: dist/apps/my-app/browser/blog/index.html
  upload: dist/apps/my-app/browser/blog/index.html
  secure: always
  expiration: "0s"

- url: /blog/introducing-my-app
  static_files: dist/apps/my-app/browser/blog/introducing-my-app/index.html
  upload: dist/apps/my-app/browser/blog/introducing-my-app/index.html
  secure: always
  expiration: "0s"

- url: /blog/added-international-support
  static_files: dist/apps/my-app/browser/blog/added-international-support/index.html
  upload: dist/apps/my-app/browser/blog/added-international-support/index.html
  secure: always
  expiration: "0s"

- url: /blog/new-blog-entry
  static_files: dist/apps/my-app/browser/blog/new-blog-entry/index.html
  upload: dist/apps/my-app/browser/blog/new-blog-entry/index.html
  secure: always
  expiration: "0s"

  # Handle default index.html
- url: /(.*)
  static_files: dist/apps/my-app/browser/index.html
  upload: dist/apps/my-app/browser/index.html
  secure: always
  expiration: "0s"

如何将“处理博客 SEO 路由”下的规则合并为一个规则?使用每个博客条目更新 app.yaml 是不可扩展的。

这个结构是从一个 Angular Universal Prerender 项目生成的。

我尝试了几种组合都没有运气:

- url: /blog/(.*)
  static_files: dist/apps/my-app/browser/blog/\1/index.html
  upload: dist/apps/my-app/browser/blog/\1/index.html
  secure: always
  expiration: "0s"

【问题讨论】:

    标签: google-app-engine angular-universal


    【解决方案1】:

    我认为您的最后一次尝试与实际解决方案非常接近。请简单地调整upload 值:

    - url: /blog/(.*)
      static_files: dist/apps/my-app/browser/\1/index.html
      upload: dist/apps/my-app/browser/(.*)/index.html
      secure: always
      expiration: "0s"
    

    正如您在 Google Cloud documentation 中看到的那样,在描述 upload 键时,您需要在其定义中提供正则表达式占位符而不是反向引用。

    请考虑在 SO 中查看类似的问题,例如 this onethis other

    【讨论】:

      猜你喜欢
      • 2021-11-27
      • 1970-01-01
      • 2013-04-09
      • 1970-01-01
      • 1970-01-01
      • 2014-09-22
      • 2015-05-15
      • 2015-01-28
      • 2019-06-13
      相关资源
      最近更新 更多