0

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)

Adam McGurk
  • 186
  • 1
  • 19
  • 54

2 Answers2

0

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.

Adam McGurk
  • 186
  • 1
  • 19
  • 54
0

Keep in mind that you still need a default service in your project, see What purpose does the default service serve in Google's app engine.

My recommendation is to make your app service the default one and drop the respective entry from the dispatch.yaml file (requests not matching any dispatch rule will be sent to the default service). Don't forget to remove the existing deployments with the app service name).

Adam's answer also applies for the auth service (you need the wildcards). From Syntax:

Tip: You can include glob patterns like the * wildcard character in the url element; however, those patterns can be used only before the host name and at the end of the URL path.

A URL pattern that can include the hostname and URL path. Glob characters can be used to match patterns. The Glob characters can be specified only at the beginning of the pattern and end of the pattern.

It's possible that the auth service appears to be running fine because it's actually served by the current default service (i.e. its older incarnation). You can check which versions and services are active in the developer console Versions page.

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97