简体   繁体   中英

React app giving 404 error when deployed to GCP

I have deployed my react app to GCP's App engine. It successfully deploys and the landing page is accessible. However none of the routes work. All the routes are giving '404' error. I am pretty sure its the app.yaml configuration that has issue. Help please!

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.

You need to either use static_files or static_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: / .

As stated in the documentation:

  • static_dir : The path to the directory containing the static files, from the application root directory. Everything after the end of the matched url pattern is appended to static_dir to form the full path to the requested file.
  • static_files : A static file pattern handler associates a URL pattern with paths to static files uploaded with the application. The URL pattern regular expression can define regular expression groupings to be used in the construction of the file path. You can use this instead of static_dir to map to specific files in a directory structure without mapping the entire directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM