【发布时间】:2021-04-28 09:08:25
【问题描述】:
我有一个 React 应用程序,我正试图在带有 GCP 的自定义域 app.[customDomain].com 上运行它。它找不到静态文件,我不知道为什么。
React 应用程序作为服务部署在 Google 云上(不是默认的,是项目中的第二个服务)。它在 Google 分配的 URL (https://[Service_ID]-dot-[Project_ID].ue.r.appspot.com/) 上完美运行。通过自定义域运行时,会加载 index.html,但找不到任何 .js 文件(因此结果是空白屏幕)并给出以下错误:
.js 文件出现 404 错误
项目中的其他服务(默认和 Django API)在同一个域上服务得很好,我的目标是让 React 应用程序在 app. 子域上服务。为了实现这一点,我有以下dispatch.yaml
dispatch:
- url: "www.[customDomain].com/"
service: default
- url: "api.[customDomain].com/"
service: default
- url: "app.[customDomain].com/"
service: React-App
我怀疑问题出在 app.yaml 的 react 应用程序中,但我无法确定需要更改的内容。这是当前的app.yaml
env: standard
runtime: nodejs14
service: React-App
handlers:
- url: /static
secure: always
static_dir: build/static
- url: /(.*\.(json|ico|js))$
secure: always
static_files: build/\1
upload: build/.*\.(json|ico|js)$
- url: .*
secure: always
redirect_http_response_code: 301
static_files: build/index.html
upload: build/index.html
我尝试将"homepage" 更改为package.json,但没有成功。
除了依赖项之外,package.json 还包含:
"name": "React-App",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:8000",
【问题讨论】:
-
您在部署期间是否在日志中获得任何相关信息/错误?您可以尝试使用设置为调试的详细程度标志重新部署以获取更多信息(只需添加
--verbosity=debugtp 您的命令)?另外,如果您重新创建自定义域会怎样? -
@RafaelLemos 使用
gcloud app deploy --verbosity=debug重新运行部署,唯一突出的是DEBUG: No bucket specified, retrieving default bucket.。否则一切似乎都很成功。重新创建自定义域是什么意思?
标签: reactjs google-app-engine google-cloud-platform subdomain