google-app-engine - 在 Google AppEngine app.yaml 中上传有什么作用?

标签 google-app-engine yaml

我有时会浏览各种 Google AppEngine 教程,我只是注意到 StackOverflow 关于 favicon.ico 的问题有些奇怪 - 特别是这个问题:favicon.ico "not found error" in app engine

- url: /favicon.ico
static_files: media/img/favicon.ico
upload: media/img/favicon.ico

- url: /robots.txt
static_files: media/robots.txt
upload: media/robots.txt

所有的发帖人都在他们的 app.yaml 定义中包含一个“upload:” 行 无论有没有 upload: 行,应用程序似乎都一样工作,我没有看到任何提及它在官方文档中。

用在什么地方,或者有没有这行有什么区别?

最佳答案

我一直在阅读 docs一遍又一遍,希望能更好地理解这一点。这是我从中推断出来的。

App Engine 说它将我们的静态文件和应用程序代码上传到不同的位置。为此,它必须知道哪些文件是静态的——这是通过上传参数指定的。

但是,这引发了一些关于 app.yaml 中指定参数的设计的问题。

  1. App Engine 是否可以仅从 static_files 参数推断出哪些文件是静态的?

    在您的示例中,static_files 参数的值与上传参数的值相同(即 media/img/favicon.ico)。但是,一般情况下,static_files 参数的值与上传参数的值不同。 static_files 参数允许将 url 模式中的匹配组替换到其中,以生成文件路径,例如
    - url:/item-(.*?)/category-(.*) static_files: 文件/\2/items/\1 上传:archives/(.*?)/items/(.*)

  2. App Engine 是否可以仅从 url 参数推断出哪些文件是静态的?

    一般来说,不,因为 url 隐含的资源层次结构可能与实际文件夹结构不相同。例如,我可能已将我的 index.html 放入子文件夹中,但我可能希望使用根 URL“hello.appspot.com/”而不是“hello.appspot.com/subfolder/”访问它。

  3. App Engine 能否同时使用 url 参数和 static_files 参数推断哪些文件是静态文件?

    编写一个返回给定 url 参数和 static_files 参数的上传模式的函数似乎是可行的,从而不需要显式上传参数。我认为它适用于简单的情况,但是,可能有一个我不知道的原因,即文档写道“处理程序无法确定您的应用程序目录中的哪些文件与给定的 url 和 static_files 模式相对应”。

    <

url: The URL pattern, as a regular expression. The expression can contain groupings that can be referred to in the file path to the script with regular expression back-references. For example, /item-(.?)/category-(.) would match the URL /item-127/category-fruit, and use 127 and fruit as the first and second groupings.
handlers:
- url: /item-(.*?)/category-(.*) static_files: archives/\2/items/\1

static_files: The path to the static files matched by the URL pattern, from the application root directory. The path can refer to text matched in groupings in the URL pattern. As in the previous example, archives/\2/items/\1 inserts the second and first groupings matched in place of \2 and \1, respectively. With the pattern in the example above, the file path would be archives/fruit/items/127.

upload: A regular expression that matches the file paths for all files that will be referenced by this handler. This is necessary because the handler cannot determine which files in your application directory correspond with the given url and static_files patterns. Static files are uploaded and handled separately from application files. The example above might use the following upload pattern: archives/(.*?)/items/(.*)



另外请注意,如果整个目录可以标记为静态,则使用 static_files 的替代方法是使用 static_dir。在这种情况下,不需要上传参数,因为 static_dir 应该指向一个实际目录,因此 App Engine 会简单地将整个目录上传到它存储静态文件的位置。但是,请注意,在这种情况下,url 参数的使用会有所不同。

url: A URL prefix. This value uses regular expression syntax (and so regexp special characters must be escaped), but it should not contain groupings. All URLs that begin with this prefix are handled by this handler, using the portion of the URL after the prefix as part of the file path.

static_dir: The path to the directory containing the static files, from the application root directory. Everything after the end of the matched url pattern is appended to static_dir to form the full path to the requested file. All files in this directory are uploaded with the application as static files.

关于google-app-engine - 在 Google AppEngine app.yaml 中上传有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2633684/

相关文章:

java - 如何调试 App Engine 生产环境中的执行暂停?

java - 从 App Engine (Java) 中删除命名空间

python,生成器迭代一个或多个项目

python - TOML,YAML和StrictYAML

go - 如何以通用方式引用嵌套 map

python - 如何将猴子补丁应用到 GAE?

maven - 退出 Google App Engine SDK 的命令是什么?

java - 错误 "The first module you upload to a new application must be the ' 默认'模块”

arrays - Prometheus 配置文件与 Puppet : how to handle quotes and brackets in yaml config file?

json - Mac cli 将 yaml 转换为 json