Reputation: 71
I have a create-react-app Build directory, put it on Cloud Storage, added an app.yaml file in as well:
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /
static_files: build/index.html
upload: build/index.html
secure: always
- url: /
static_dir: build
Hosted on app engine and voila - it works!
However, while example-domain.com/ works, example-domain.com/abc doesn't. I get Error: Not Found The requested URL /abc was not found on this server.
I tried replacing "/" with "/.*" in the handler url, but the result returns a blank page :(.
Any suggestions? :)
Upvotes: 2
Views: 2456
Reputation: 71
Found the solution. Turns out when I use static_dir, every url that starts that starts with that handler's url is included. Given that every static file is in the build/static dir, I just used url: /static for anything that needs to be handled from that folder.
Create-react-app creates several .json files which are in the build dir, so I just pointed to them individually since there only a few.
After all this is done I can use url: /.* to imply that any other url should just point to the index.html page.
This works: (The first handler is probably redundant)
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
Upvotes: 3
Reputation: 11370
First, you have duplicate handlers for /
. You will never get to the second handler.
You can serve static files of whatever kind you want using some regex in your handler, like so:
- url: /(.*\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg|html))$
static_files: build/\1
upload: build/.*\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg|html)$
secure: always
Upvotes: 1