Reputation: 689
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.
- 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.
error_handlers:
- file: 404.html
to do something for me, but no, it seems to not do anything at all.
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!
Upvotes: 0
Views: 105
Reputation: 4670
Indeed, there is not easier way for you to achieve the custom 404
page, then adding a custom script to create the 404
response. App Engine, unfortunately, still doesn't work very well with handling some errors, which includes the error 404
. As you can check in this official documentation here, there is no custom handlers from this error on Java.
This is just an example that a custom script is the viable solution.Otherwise, the solutions won't return the error 404
- as you well mentioned - or you would need to use a catch-all handler, which is not very recommended as well, since it's too broad of a solution.
In case you are using Python, there is a very good example of how to configure the trigger and example of script here.
Let me know if the information helped you!
Upvotes: 1