0

Battling to get this to work. I have an app composed of two services - frontend in Angular, backend in Node.

dispatch:

  - url: "<frontend-app>-dot-apt-aleph-767.appspot.com/"
    service: <frontend-app>
  - url: "<frontend-app>-dot-apt-aleph-767.appspot.com/backend/"
    service: <backend-app>

This is the output from gcloud app describe:

dispatchRules:
- domain: <frontend-app>-dot-apt-aleph-767.appspot.com
  path: /
  service: <frontend-app>

- domain: <frontend-app>-dot-apt-aleph-767.appspot.com
  path: /backend/*
  service: <frontend-app>

When I navigate to the url for the frontend app, it works as expected. However, I get a 404 when I go to <frontend-app>-dot-apt-aleph-767.appspot.com/backend. It doesn't make sense because when I navigate straight to the backend URL, it works as expected.

plzhalp.

Mina
  • 610
  • 7
  • 21

1 Answers1

1

For this to work you need your backend service to handle requests to both /<somepath> and /backend/<somepath> in an identical manner.

Check your backend app log and you'll see that the request you were expecting it to handle but which it responded to with the 404 contains a /backend prefix, while the request going straight to the backend URL doesn't.

Also note that the order of the dispatch rules matters - you want the more specific one first, otherwise it'll never be reached since the more generic one will match the request before it. And you may want to put some wildcards as well on the request path:

dispatch:
- url: "<frontend-app>-dot-apt-aleph-767.appspot.com/backend/*"
  service: <backend-app>
- url: "<frontend-app>-dot-apt-aleph-767.appspot.com/*"
  service: <frontend-app>

Further refining this:

  • the last URL can be dropped as it is redundant - that's the default routing by URL behaviour
  • since the backend service needs to handle /backend/* as well you can wildcard the host part of the 1st URL, which would be useable as-is with both appspot.com and a custom domain (if you ever get one):

So just this should suffice:

dispatch:
- url: "*/backend/*"
  service: <backend-app>

Alternatively you can drop the "<frontend-app>-dot-apt-aleph-767.appspot.com/backend/" URL from the dispatch file and teach your frontend service to accept, but redirect any /backend/<somepath> requests it sees to <backend-app>-dot-apt-aleph-767.appspot.com/<somepath>.

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