Home > Enterprise >  Google App Engine: Static file referenced by handler not found
Google App Engine: Static file referenced by handler not found

Time:07-23

I have no experience with web hosting and I've been trying for days to get my (Spring Boot Angular) app up and running. Please help!

I can't figure out the routing of requests. Here is the structure of my server app:

src
  main
    appengine
      app.yaml
    java
    resources
pom.xml

I use maven-resources-plugin to ng build and copy my frontend (which is in a different folder) into ${basedir}/target/classes/static when I deploy my app.

Now here are my app.yaml handlers:

handlers:
  # Direct these to the server's endpoints
  - url: /api/.*
    script: auto
  # Direct these to index.html and let the frontend routes do their thing
  - url: /.*
    static_files: static/front/index.html # this does not work
    upload: static/front/index.html       # this does not work

At the moment when I try to reach mywebsite.com/some-page, the request is routed to my server and, since the /some-page endpoint doesn't exist, I get the "The requested URL / was not found on this server" error (and "Static file referenced by handler not found" in the server logs).

My question is, what path should I put in static_files here, so that my requests that don't contain /api/ don't all get routed to the server app?

Furthermore I tried moving app.yaml to the project root to make this easier but deployment (mvn package appengine:deploy) fails because it doesn't find the file /src/main/appengine/app.yaml.

Edit: For what it's worth, here's the location of index.html when I explore the JAR:

my-website.jar
  META-INF
  BOOT-INF
    classes
      com
        purrfectdoodle
          back
            service <----------- These are the project packages
            model
            repository
            ...
      static
        front
          index.html <---------- HERE

CodePudding user response:

An error in an application's app.yaml frequently causes the error static file referenced by handler not found. It basically means that one of app.yaml's static file handlers is diverting to a file that does not exist or is named wrongly. It would be recommended as a strategy if you use a technique to differentiate files from directories. You can achieve something like this by stating that all filenames must have extensions (and folders most not. in their names):

/optional/path/folder/ - serve index.html inside
- url: /(.*)/ static_files: public/\1/index.html upload: public/.*/index.html /optional/path/name.extension => files - serve them
- url: /((.*\/)*[^\/] \.[^\/] )$ static_files: public/\1 upload: public/.*
anything else is a folder - serve index.html inside
- url: /(.*)$ static_files: public/\1/index.html upload: public/.*/index.html

Please be advised that all this depends on your directory structure. The order is significant, as is the use of /. instead of /.* With the latter, requests for / would get routed to the main.app

Here is also reference for the app.yaml configurations[1] and structuring web services documentation [2] that could help.

[1] : https://cloud.google.com/appengine/docs/standard/python3/config/appref

[2] : https://cloud.google.com/appengine/docs/standard/java-gen2/configuration-files

  • Related