Google App Engine静态网站处理程序通配符路由

时间:2018-06-27 17:51:13

标签: google-app-engine app.yaml

我有一个使用create-react-app的React.js网站,并且刚刚从Firebase托管移至Google App Engine标准环境。

借助Firebase托管,我可以创建https://example.com/routehttps://example.com/newRoute/123之类的路由,并且Firebase知道可以为这些路由中的任何一个提供index.html。

我想通配我们应用程序的任何路由以使用index.html,同时排除.js和.css文件。如果仅使用通配符/(.*),则对main.js文件的请求也将解析为index.html。

这是我们的处理程序配置

handlers:
  - url: /
    secure: always
    application_readable: false
    static_files: build/index.html
    require_matching_file: false
    upload: build/index.html
  - url: /login
    secure: always
    application_readable: false
    static_files: build/index.html
    require_matching_file: false
    upload: build/index.html
  - url: '/(.*)'
    secure: always
    application_readable: false
    static_files: "build/\\1"
    require_matching_file: false
    upload: 'build/.*'

在当前配置中,我创建的每个路由都必须注册为处理程序。我希望找到一种解决方案,其中所有当前路由和将来的路由都可以由通配符处理。

1 个答案:

答案 0 :(得分:1)

处理程序的顺序很重要,具有匹配模式的第一个处理程序将获胜。

因此,要实现所需的目标,可以先“处理通配符” Error in .verify.JDBC.result(s, "Unable to execute JDBC prepared statement ", : Unable to execute JDBC prepared statement SELECT i.event_date, i.id, i.id2, i.id3, i.id4, i.id5, COUNT(i.sales) sales, COUNT(c.volume) volume FROM table1 i LEFT JOIN table2 c ON i.id = c.id AND i.id2 = c.id2 AND i.id3 = c.id3 WHERE i.event_date = DATE('2018-06-18') AND i.id IN ( (Method Connection.prepareStatement is not yet implemented) ,然后再处理异常。遵循这些原则(我假设index.html.css文件也相对于.js目录):

build

旁注:为了便于阅读,我还删除了handlers: - url: /(.*\.css)$ secure: always static_files: build/\1 upload: build/.*\.css$ - url: /(.*\.js)$ secure: always static_files: build/\1 upload: build/.*\.js$ # continue similarly the other static assets # or maybe try a more generic one covering several of them: - url: /(.*\.(js|css|png|jpg|svg))$ secure: always static_files: build/\1 upload: build/.*\.(js|css|png|jpg|svg)$ # wildcard everything else, serving index.html - url: '/(.*)' secure: always static_files: build/index.html upload: build/index.html (在GAE中没有这种东西)和require_matching_file(默认情况下为false)。