I have two different services in my App Engine app, called auth and app. The auth service works perfectly fine, the images, css, js, and php are all served and executed properly. The auth service was also my default service when I first launched the App Engine app.
My problem is the app service. At first all I was getting was just a bunch of too many redirect errors, but then I was able to fix that, but now none of the CSS JS, or images are being served properly by the app service. The only CSS that's being served is actually from the auth service and there is no JS being served, and there is one background image from the auth service being served. Again, these are two completely different things and are even living in their own custom subdomain.
And, in addition, the router from my auth service, is being used as the router for my app service.
I think all of these problems have to do with my default service (which I shouldn't even be using anymore) interfering with my app service (and it wouldn't affect my auth service because they're one in the same I think when it comes to the google cloud). Here is my app.yaml. It is the same for both services except for the service name and the router name:
runtime: php73
service: app
entrypoint: serve /approuter.php
handlers:
- url: /assets
static_dir: assets
# Serve static files as static resources.
- url: /(.+\.(gif|png|jpg|svg|webp|jpeg|js))$
static_files: \1
upload: .+\.(gif|png|jpg|svg|webp|jpeg|js)$
- url: /style
static_dir: style
- url: /js
static_dir: js
- url: /.*
script: auto
And this is my dispatch.yaml:
dispatch:
- url: "app.example.com/"
service: app
- url: "auth.example.com/"
service: auth
So here is ultimately my question:
How can I get a true seperation of concerns when it comes to different services? (ie...not having the default service serve everything to my app service)
So this answer was really easy, but again, it's not documented anywhere, so I want to give a pretty in-depth answer here.
The TLDR; answer is below (dispatch.yaml):
dispatch:
- url: "app.example.com/*"
service: app
- url: "auth.example.com/*"
service: auth
Literally just adding a * at the end of each path...let's dive into this though and talk about it.
FIRST remember that my default service was what has now become the "auth" service. This will be important soon.
I think everybody understands what's going on here...the *
after the domain name means that it needs to match any url that points to that domain. What was happening without the *
was that the only path served by the service was my root path (or /
). Everything else was handled by the default service....which brings us to why I was seeing static assets from the default service in my app service.
When App Engine would encounter a URL that wasn't specifically handled by the dispatch.yaml (so anything besides the roots for app.example.com and auth.example.com) it would "default" to the default service, which, if you remember, was my auth service. Which is why my auth service seemed like it was working perfectly, while my app service had issues.
So, to wrap up, adding the star to the dispatch URLs allowed app engine to navigate to the correct subfolders.