yaml处理程序配置

yaml处理程序配置

本文介绍了正确的html网站的Google App Engine正确的app.yaml处理程序配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我网站的文件结构:

Here is the file structure of my website:

public
│   404.html
│   app.yaml
│   index.html
│   index.xml
│   prereqs.zip
│   sitemap.xml
│   sof2018.py
|
├───categories
│       index.html
│       index.xml
├───css
│       styles.css
├───home
│       index.html
├───js
│       scripts.js
├───prerequisites
│       index.html
├───scripts
│   │   index.html
│   │   index.xml
│   │
│   ├───page
│   │   └───1
│   │           index.html
│   │
│   └───sof2018
│           index.html
├───tags
│       index.html
│       index.xml
└───usage
        index.html

基本上,我需要确保以下几点:

Basically I need to ensure the following:


  • 如果有任何带有斜杠的文件夹被调用(例如 / scripts / page / 1 / / home / ),则应在该文件夹中查找index.html

  • 如果调用了没有斜杠的任何文件夹(例如 / scripts / page / 1 / home ),它应该看起来像用于该文件夹中的index.html

  • 是否有文件(例如 / css / s tyles.css /prereqs.zip )被调用,它应该返回文件

  • if any folder is called with trailing slash (say /scripts/page/1/ or /home/), it should look for index.html inside that folder
  • if any folder is called without trailing slash (say /scripts/page/1 or /home), it should look for index.html inside that folder
  • if any file (say /css/styles.css or /prereqs.zip) is called, it should return the file

区分文件和文件夹的方法可能是简单地检查是否存在句点(。),因为我的所有文件都有扩展名。虽然我猜想其他人也可以从处理无扩展名文件的解决方案中受益。

The way to differentiate between files and folders could be to simply to check if there is a period(.) since all my files have extensions. Though I guess someone else might benefit with a solution that handles extension-less files also.

我尝试了许多不同的正则表达式,它们似乎都漏掉了某些情况。还几乎在同一件事上尝试了关于堆栈溢出的先前问题中提出的所有解决方案。

I have tried a number of different regexes, all of them seem to missing out some case or the other. Also tried all the solutions proposed in previous questions on stackoverflow on pretty much the same thing.

我不是在寻找适合我的网站的app.yaml,

I'm not looking for an app.yaml tailor-made for my website, that can be done by manually dealing with each of the folders, cases, etc.

我正在寻找一种通用解决方案,该解决方案可以与传统方式完全一样网络托管服务商可以工作,因为我猜想这也会对其他人也有利。然后,我可以自由添加/更改内容/结构,而不必每次都更新app.yaml。

I'm looking for a general solution that would work exactly how a traditional web host would work, since I'm guessing that would benefit others as well. Then I'll be free to add/change content/structure without having to update app.yaml every time.

P.S。老实说,谷歌应该自己提供解决方案,但事实并非如此。我猜想即使是适当的Web开发人员也不是regex的主人。

P.S. In all honesty, google should have themselves provided the solution, but they haven't. I'm guessing even proper web devs aren't regex masters.

P.S.2该网站是使用Hugo静态网站生成器制作的。我可以确认它可以在传统的网络主机(GoDaddy)上运行。另外,我对HTML / CSS / JS的了解不足,无法确定该网站的实际内部运作情况;

P.S.2 The website is made using the Hugo static site generator. I can confirm it is working on a traditional web host (GoDaddy). Also I don't know enough html/css/js to tell for sure what is the actual internal working of the site; if required I can provide the source files.

推荐答案

您不能在完全静态的GAE(标准环境)中实现所有这些功能网站。这是因为您无法提前告知(例如,在创建app.yaml配置时) / some / path / item 是文件还是文件夹,因此 / some / path / item 或 /some/path/item/index.html

You cannot achieve all of this on (standard environment) GAE with a completely static website. That's because you have no way of telling ahead of time (i.e. when creating the app.yaml config) if /some/path/item is a file or a folder and thus /some/path/item or /some/path/item/index.html should respectively be returned.

写正确的正则表达式不是问题,而是要为相同提供2个不同结果regex。

It's not a matter of writing the right regex, it's a matter of wanting 2 different outcomes for the same regex.

要实现所需的功能,您需要该应用在运行时检查条件并做出决定-不再是静态站点。

To achieve what you want you need the app to check the condition at runtime and make the decision - not a static site anymore.

如果您放下第二颗子弹,您可以通过以下方法实现其余目标:

If you drop your 2nd bullet you can achieve the rest with this:

- url: /(.*)/
  static_files: public/\1/index.html
  upload: public/.*/index.html

- url: /(.*)$
  static_files: public/\1
  upload: public/.*

如果您可以从文件夹中区分文件,则可以提出一个方案。例如,通过指定所有文件名都必须具有扩展名(目录名称中不能包含),则可以执行以下操作:

If you have a way of differentiating files from folders you may be able to come up with a scheme. For example by specifying that all filenames must have extensions (and directories cannot have . in their names), then you can do something like this:

# /optional/path/folder/ - serve index.html inside
- url: /(.*)/
  static_files: public/\1/index.html
  upload: public/.*/index.html

# /optional/path/name.extension => files - serve them
- url: /((.*\/)*[^\/]+\.[^\/]+)$
  static_files: public/\1
  upload: public/.*

# anything else is a folder - serve index.html inside
- url: /(.*)$
  static_files: public/\1/index.html
  upload: public/.*/index.html

这篇关于正确的html网站的Google App Engine正确的app.yaml处理程序配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 15:51