1

I'm developing an application using react js and nodejs.When I run the application in local machine it works properly as a example

localhost:3000/AboutUs
localhost:3000

When I refresh the above URLs, it shows the correct web page. I deploy this application in Google App Engine and when I refresh the below page it shows that the requested URL was not found. Can any one let me know the reason for this?

www.mydomain.com/AboutUs

app.yaml code is as below

runtime: nodejs8
handlers:
- url: /api/.*
# secure: always
# redirect_http_response_code: 301
script: auto
- url: /
static_files: build/index.html
upload: build/index.html
Thusila Bandara
  • 285
  • 3
  • 21

1 Answers1

2

It's because you don't have a defined handler to direct your /AboutUs URL. You can either add, under handlers:

- url: /AboutUs
  script: auto

Or add a wildcard handler at the end of the url list, for example:

runtime: nodejs8
handlers:
- url: /api/.*
# secure: always
# redirect_http_response_code: 301
  script: auto
- url: /
  static_files: build/index.html
  upload: build/index.html
- url: /.*
  script: auto

It's important to keep the wildcard handler /.* at the end, since otherwise all the URL's will fall under it, and it won't use the other url handlers.

Also you had two spaces missing in the script,static_files and upload tags under the url's, I don't know if it was because of the formatting when copying the app.yaml contents to your answer, but either way, indentation is important in YAML files.

Joan Grau Noël
  • 2,766
  • 7
  • 18
  • Actually I need to have this wildcard handler but it is not working – Thusila Bandara Jan 16 '19 at 13:26
  • You can compare your application to [this one](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/appengine/hello-world/standard) to find any differences that might be causing the issue. Check that you have an `express` entry-point in the `app.js` file (with your application handlers defined under it). As well, check the `package.json` file, it should specify the [application startup](https://cloud.google.com/appengine/docs/flexible/nodejs/runtime#application_startup) and the dependencies you are using. – Joan Grau Noël Jan 16 '19 at 14:10
  • This sort of approach didn't work for me. What worked for me was the app.yaml handlers written in this question (yes, the question, it's been turned into an answer): https://stackoverflow.com/questions/54247953/how-do-i-setup-routing-for-react-in-gae-directly-routing-to-react-router-dom-ro – Andrew Puglionesi Jul 07 '19 at 01:39