Google App Engine - 为特定的 url 编写 app.yaml,例如 applicationName.appspot.com/docs/ec-quickstart/index.html

Google App Engine - Writing app.yaml for a particular url like applicationName.appspot.com/docs/ec-quickstart/index.html

我有一个 google 应用程序引擎应用程序,我正在使用 python 27。 我希望我的 url 部署后为 applicationName.appspot.com/docs/ec-quickstart/index.html

如何编写我的 app.yaml 文件?

下面的代码加载了我的 index.html 文件,但没有 css。

  handlers:

  - url: /docs/ec-quickstart/index.html
  static_files: docs/ec-quickstart/index.html
  upload: docs/ec-quickstart/index.html

但是,如果我将文件更改为

  handlers:

  - url: /(.*)
  static_files: docs/ec-quickstart/
  upload: docs/ec-quickstart/(.*)

  - url: /docs/ec-quickstart/index.html
  static_files: docs/ec-quickstart/index.html
  upload: docs/ec-quickstart/index.html

url applicationName.appspot.com

的 css 可以正确加载所有内容

我希望 url 映射到 applicationName.appspot.com/docs/ec-quickstart/index.html

您需要为要提供的每件作品指定规则,并构建您的 html 以相应地引用它们。请注意模式,因为 将使用第一个匹配项,即使下面有更具体的匹配项也是如此。

第一次尝试没有指定您的 .css 文件所在的位置。

第二次尝试表明您的 .css 文件与 index.html 文件位于同一目录中,并且都仅使用第一条规则提供服务(index.html 也匹配,第二条规则实际上没有被使用。

因此您可以只使用一个匹配两个文件的规则,但修改 html 以将 css 引用为 /docs/ec-quickstart/blah。css:

  - url: /docs/ec-quickstart/(.*)
  static_files: docs/ec-quickstart/
  upload: docs/ec-quickstart/(.*)

或者仍然使用 2 条规则(其他部分可能更多,但要确保各自的模式不匹配 index.html),不进行 html 修改:

  - url: /(.*\.css)$
  static_files: docs/ec-quickstart/
  upload: docs/ec-quickstart/(.*\.css)$

  - url: /docs/ec-quickstart/index.html
  static_files: docs/ec-quickstart/index.html
  upload: docs/ec-quickstart/index.html

Dan Cornilescu 建议的答案非常有效。对于遇到同样问题的其他人,这是我想出的另一种方法。

  handlers:

  - url: /docs/ec-quickstart
    static_dir: docs/ec-quickstart