如何正确格式化 app.yaml 以使用 PHP 后端托管 Flutter Web 应用程序

How to properly format app.yaml to host Flutter web app with PHP backend

我正在尝试为具有 php 后端的 flutter web 应用程序创建一个 .yaml 文件,但我 运行 遇到了奇怪的问题。

该应用的结构如下:

flutter 应用程序位于 Admin/web/ 中,包括各种文件类型但没有 php 文件。着陆页是 index.html.

PHP 后端在 Admin/ 中。所有 PHP 文件都需要来自 Admin/

它当前加载 index.html,但由于某些原因,当我尝试网站时。com/manifest。json,我再次获得 index.html。这同样适用于 FontManifest.json——它给了我 index.html.

对网站根目录(website.com/)、index.html、main.dart.js有效--对应文件传输准确

这是我的 .yaml 文件:

service: admin
runtime: php72


handlers:

  - url: /(.+\.(ico|jpg|png|gif))$
    static_files: Admin/web/
    upload: Admin/web/(.+\.(ico|jpg|png|gif))$
    login: admin
    secure: always


  - url: /(.+\.(htm|html|css|js|json|map|ttf|dart))$
    static_files: Admin/web/
    upload: Admin/web/(.+\.(htm|html|css|js|json|map|ttf|dart))$
    login: admin
    secure: always


  - url: /(.+\.php)$
    static_files: Admin/
    upload: Admin\/(.+\.php)$
    login: admin
    secure: always

  - url: /(.*)$
    static_files: Admin/web/index.html
    upload: Admin/web/(.*)$
    login: admin
    secure: always

我注意到页面立即从 website.com/ 重定向到 website.com/#/,所以我也尝试了这个 .yaml 文件:

service: admin
runtime: php72

handlers:

  - url: /(.+\.(ico|jpg|png|gif))$
    static_files: Admin/web/
    upload: Admin/web/(.+\.(ico|jpg|png|gif))$
    login: admin
    secure: always

  - url: /#/(.+\.(ico|jpg|png|gif))$
    static_files: Admin/web/
    upload: Admin/web/(.+\.(ico|jpg|png|gif))$
    login: admin
    secure: always

  - url: /(.+\.(htm|html|css|js|json|map|ttf|dart))$
    static_files: Admin/web/
    upload: Admin/web/(.+\.(htm|html|css|js|json|map|ttf|dart))$
    login: admin
    secure: always

  - url: /#/(.+\.(htm|html|css|js|json|map|ttf|dart))$
    static_files: Admin/web/
    upload: Admin/web/(.+\.(htm|html|css|js|json|map|ttf|dart))$
    login: admin
    secure: always

  - url: /(.+\.php)$
    static_files: Admin/
    upload: Admin\/(.+\.php)$
    login: admin
    secure: always

  - url: /(.*)$
    static_files: Admin/web/index.html
    upload: Admin/web/(.*)$
    login: admin
    secure: always

不过,使用这个 .yaml 文件,我得到了相同的结果。

编辑 我意识到由于处理程序的顺序,之前的 .yaml 文件会产生与原始文件相同的结果,因此我尝试了以下操作(并得到了相同的结果):

service: admin
runtime: php72

handlers:

  - url: /#/(.+\.(ico|jpg|png|gif))$
    static_files: Admin/web/
    upload: Admin/web/(.+\.(ico|jpg|png|gif))$
    login: admin
    secure: always

  - url: /(.+\.(ico|jpg|png|gif))$
    static_files: Admin/web/
    upload: Admin/web/(.+\.(ico|jpg|png|gif))$
    login: admin
    secure: always

  - url: /#/(.+\.(htm|html|css|js|json|map|ttf|dart))$
    static_files: Admin/web/
    upload: Admin/web/(.+\.(htm|html|css|js|json|map|ttf|dart))$
    login: admin
    secure: always

  - url: /(.+\.(htm|html|css|js|json|map|ttf|dart))$
    static_files: Admin/web/
    upload: Admin/web/(.+\.(htm|html|css|js|json|map|ttf|dart))$
    login: admin
    secure: always

  - url: /(.+\.php)$
    static_files: Admin/
    upload: Admin\/(.+\.php)$
    login: admin
    secure: always

  - url: /(.*)$
    static_files: Admin/web/index.html
    upload: Admin/web/(.*)$
    login: admin
    secure: always

编辑

原因显然是上传处理程序只需要保留扩展的捕获组。为什么这是我不知道的。

所以,这是一个更正确的答案,尽管我不知道这背后的原因。

service: admin
runtime: php72

entrypoint: serve Admin/front.php

handlers:

  - url: /(.+\.(ico|jpg|png|gif))$
    static_files: Admin/web/
    upload: Admin/web/.+\.(ico|jpg|png|gif)$
    login: admin
    secure: always

  - url: /(.+\.(htm|html|css|js|json|map|ttf|dart))$
    static_files: Admin/web/
    upload: Admin/web/.+\.(htm|html|css|js|json|map|ttf|dart)$
    login: admin
    secure: always

  - url: /
    static_files: Admin/web/index.html
    upload: Admin/web/index.html
    login: admin
    secure: always

--旧版本--

好的,秘诀就是不要以 $ 结束 URL 模式。

这是工作页面:

service: admin
runtime: php72

entrypoint: serve Admin/front.php

handlers:

  - url: /(.+\.(ico|jpg|png|gif))
    static_files: Admin/web/
    upload: Admin/web/(.+\.(ico|jpg|png|gif))
    login: admin
    secure: always

  - url: /(.+\.(htm|html|css|js|json|map|ttf|dart))
    static_files: Admin/web/
    upload: Admin/web/(.+\.(htm|html|css|js|json|map|ttf|dart))
    login: admin
    secure: always

  - url: /
    static_files: Admin/web/index.html
    upload: Admin/web/index.html
    login: admin
    secure: always

我用 entrypoint: serve Admin/front.php 服务 php。