I have app engine an app with some static pages.
I want to serve my static content, and a script. Finally, I want to serve 404 for everything else.
My app.yaml file looks something like
runtime: go113
handlers:
- url: /myscripy
script: auto
- url: /$
static_files: public/index.html
secure: always
upload: public/index.html
- url: /(.*/)?$
static_files: public/\1index.html
secure: always
upload: public/(.*/)?index.html
http_headers:
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Frame-Options: SAMEORIGIN
OK, that's working except a few things
it's unclear to me why the
- url: /$
is necessary, why is it not subsumed by- url: /(.*/)?$
, but that's just a side note.main problem: any URL that matches nothing will be rendered as empty file with a 200 status code instead of a 404.
I can force 404s by adding something like
- url: /.*
static_files: public/some_non_existing_file.html
secure: always
upload: public/some_non_existing_file.html
at the end of the app.yaml file, but that triggers an ugly 404 last ditch page that is not very appealing.
- I can serve nice 404 custom pages like
- url: /.*
secure: always
static_files: public/404.html
upload: public/404.html
http_headers:
Status: 404
where public/404.html exists, however the Status: 200 header is sent before the Status: 404 header, making the whole response a 200.
- I had hopes for
error_handlers:
- file: 404.html
to do something for me, but no, it seems to not do anything at all.
- I can of course add a custom script to create the 404 response, but it feels a bit silly to me. Isn't there a better way ?
I'm a bit stumped - I can't believe that a long standing industry tool like GAE has no way to statically define a custom 404 page, or even render 404 status code for nonexisting pages.
Really appreciate any advice, thanks in advance!