0

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
Sarah Remo
  • 614
  • 1
  • 9
Eva
  • 99
  • 1
  • 7
  • You may check [this] (https://stackoverflow.com/questions/1058119/how-to-redirect-all-urls-with-google-app-engine) post referencing a similar issue – Vaidehi Jamankar Jun 16 '22 at 13:26
  • I believe the path for ```static_files``` is from the root of your application. If so, is your ```static``` folder (which you have referenced) in the root of your application? – NoCommandLine Jun 16 '22 at 16:00
  • @NoCommandLine See my edit + the bit about `maven-resources-plugin`: since the JAR kind of makes up its own structure compared to the raw project folder, I'm really not sure what the "root of the application" is supposed to be. Is it `mywebsite.jar/`? `mywebsite.jar/BOOT-INF`? etc. – Eva Jun 16 '22 at 17:33
  • @Eva,Let me know if my recommendations worked. – Vaidehi Jamankar Jul 08 '22 at 04:42

1 Answers1

0

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

Vaidehi Jamankar
  • 1,232
  • 1
  • 2
  • 10
  • Thanks for your answer. "all this depends on your directory structure" -> this is my actual problem though: I can't seem to write the proper path based on the directory structure I have detailed in my question. – Eva Jun 20 '22 at 09:23
  • The path to the directory containing the static files, from the application root directory. Everything after the end of the matched url pattern is appended to static_dir to form the full path to the requested file.Static files cannot be the same as application code files. If a static file path matches a path to a script used in a dynamic handler, the script will not be available to the dynamic handler.Check [static_dir here](https://cloud.google.com/appengine/docs/standard/python/config/appref?csw=1#handlers_application_readable) – Vaidehi Jamankar Jun 21 '22 at 05:18