简体   繁体   English

React 应用程序在部署到 GCP 时出现 404 错误

[英]React app giving 404 error when deployed to GCP

I have deployed my react app to GCP's App engine.我已将我的反应应用程序部署到 GCP 的应用程序引擎。 It successfully deploys and the landing page is accessible.它成功部署并且可以访问登录页面。 However none of the routes work.然而,这些路线都不起作用。 All the routes are giving '404' error.所有路线都给出“404”错误。 I am pretty sure its the app.yaml configuration that has issue.我很确定它的 app.yaml 配置有问题。 Help please!请帮忙!

app.yaml app.yaml

runtime: nodejs10

handlers:
- url: /
  static_files: build/index.html
  upload: build/index.html

- url: /
  static_dir: build

The issue is that you are using both static_files and static_dir to your / url.问题是您在/ url 中同时使用了static_filesstatic_dir

You need to either use static_files or static_dir .您需要使用static_filesstatic_dir

From the description of your question it looks like you want to use static_dir to match everything that is inside the directory after the url: / .从您的问题的描述看来,您想使用static_dir来匹配url: /之后目录中的所有内容。

As stated in the documentation:如文档中所述:

  • static_dir : The path to the directory containing the static files, from the application root directory. static_dir :从应用程序根目录到包含 static 文件的目录的路径。 Everything after the end of the matched url pattern is appended to static_dir to form the full path to the requested file.匹配的 url 模式结束后的所有内容都附加到 static_dir 以形成请求文件的完整路径。
  • static_files : A static file pattern handler associates a URL pattern with paths to static files uploaded with the application. static_files :static 文件模式处理程序将 URL 模式与随应用程序上传的 static 文件的路径相关联。 The URL pattern regular expression can define regular expression groupings to be used in the construction of the file path. URL 模式正则表达式可以定义用于构建文件路径的正则表达式分组。 You can use this instead of static_dir to map to specific files in a directory structure without mapping the entire directory.您可以使用它代替 static_dir 到 map 到目录结构中的特定文件,而无需映射整个目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React 应用程序在 localhost 上运行,但在 github 或 heroku 上部署时出错。 部署时没有错误 - React app working on localhost but giving error when deployed either on github or on heroku. No error while deploying React Flask 应用程序可在 Docker 容器中运行,但在部署到 Cloud Run 时返回 404 错误 - React Flask app works in Docker container but returns 404 error when deployed to Cloud Run 尝试从部署的 create-react-app 中的公用文件夹中获取 json 文件时出现 404 错误 - 404 Error when trying to fetch json file from public folder in deployed create-react-app 部署在 Digital Ocean 上的 React App 出现 404 错误 - React App deployed on Digital ocean gives 404 Error 部署的 React 应用程序显示一个空白页面并且控制台返回错误 404 - Deployed React App Shows a Blank Page and Console Returns Error 404 部署到 GitHub 的 React 应用程序给了我一个缩小的错误 #152 - React app deployed to GitHub giving me a minified error #152 部署时反应路由器无匹配 404 不起作用? - React router No Match 404 not working when deployed? 应用部署到生产服务器时返回 404 - App returns 404 when deployed to production server React 应用程序在本地工作,但部署到 heroku 时出现应用程序错误 - React app working locally but application error when deployed to heroku React App在主js和css上给出404 - React App giving 404 on main js and css
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM