我有一个 create-react-app Build 目录,将其放在 Cloud Storage 上,还添加了一个 app.yaml 文件:
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /
static_files: build/index.html
upload: build/index.html
secure: always
- url: /
static_dir: build
托管在应用程序引擎上,瞧 - 它有效!
但是,虽然example-domain.com/可以工作,example-domain.com/abc却不能。我收到错误:未找到 在此服务器上找不到请求的 URL/abc。
我尝试将处理程序 URL 中的“/”替换为“/.*”,但结果返回空白页:(。
有什么建议吗? :)
最佳答案
找到了解决方案。结果当我使用 static_dir 时,包含以该处理程序的 url 开头的每个 url。鉴于每个静态文件都位于 build/static 目录中,我只使用 url:/static 来处理需要从该文件夹处理的任何内容。
Create-react-app 创建了几个位于构建目录中的 .json 文件,所以我只是单独指向它们,因为只有几个。
完成所有这些后,我可以使用 url:/.* 来暗示任何其他 url 应该只指向 index.html 页面。
这有效:(第一个处理程序可能是多余的)
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /
static_files: build/index.html
upload: build/index.html
secure: always
- url: /static
static_dir: build/static
- url: /manifest.json
static_files: build/manifest.json
upload: build/manifest.json
- url: /asset-manifest.json
static_files: build/asset-manifest.json
upload: build/asset-manifest.json
- url: /service-worker.json
static_files: build/service-worker.json
upload: build/service-worker.json
- url: /pageIcon.png
static_files: build/pageIcon.png
upload: build/pageIcon.png
- url: /.*
static_files: build/index.html
upload: build/index.html
secure: always
关于javascript - 如何在 GAE 中使用 app.yaml 获取适用于静态文件的任何 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50091348/