Semantics of dispatch.yaml
Asked Answered
F

2

7

I'm looking at various pages about dispatch.yaml, most of which contain similar information and examples:

https://cloud.google.com/appengine/docs/flexible/nodejs/how-requests-are-routed#routing_with_a_dispatch_file https://cloud.google.com/appengine/docs/python/config/dispatchref https://cloud.google.com/appengine/docs/go/config/dispatchref etc.

I happen to be using node.js on GAE Flexible Environment, but I think it would be the same for every language and environment.

The problem is that these pages don't really specify how dispatch.yaml works. In particular:

  1. Are rules applied in the order given? I'm assuming that the first matching rule is the one used, but nothing seems to say so.
  2. Do leading glob (wildcard) characters match only the domain name, or could they match the first part of the URL's path? If the rule is */hello, would that match myapp.appspot.com/path/hello? I'm guessing not, based on some vague hints in the docs, but it isn't very clear.
  3. If no rule in dispatch.yaml matches the URL, will it be routed to the default service? I would think it would have to, but again, these pages don't say.
  4. Do URLs get rewritten based on the rules before they're sent to the service? If the rule is */path/* and the URL is https://myapp.appspot.com/path/hello, will the service see it as /path/hello or as /hello? I'm guessing the former.

I'm doing some trial and error now, so I may be able to answer my own question soon. I'm also submitting this to Google through their documentation feedback system.

Freesia answered 28/10, 2016 at 20:2 Comment(0)
F
7

Things I know so far:

  1. Yes, rules are tried in order. So for example, if you want one URL to go to a specific service, and all other URLs to go to another service, you should specify the specific one first:
dispatch:
  - url: "*/specific"
    module: specific

  - url: "*/*"
    module: general

If you put those rules in the opposite order, module specific will never be used, because the URL /specific will be caught by the wildcard rule.

  1. Unknown

  2. Yes. You can test this by making a request not matching any dispatch.yaml rule and watching the default's service logs.

  3. No rewriting. If the rule is */path/* and the actual URL is https://myapp.appspot.com/path/hello, your service should still handle /path/hello, not /hello.

Freesia answered 1/12, 2016 at 18:51 Comment(2)
An additional "thing to know" is that one must deploy dispatch.yaml deliberately: simply deploying an app with default CLI params (ie glcoud app deploy --project my-project) will deploy app.yaml, cron.yaml, queue.yaml and index.yaml if found in the project root, but will not deploy dispatch.yaml. Without deploying dispatch.yaml, all requests will continue to go to the default Service.Cossack
@Cossack Amazing, this comment from two years ago on this question with barely any views is where I find out this information. Life saver.Translocation
G
1

Just to fill in the blank (feel free to paste this into the accepted answer):

  1. No. It only matches the start of the path.

I created two apps with the following resources:

default -> /abc/def/test.html -> <h1>default</h1>
other -> /abc/def/test.html -> <h1>other</h1>

And 1 route:

<dispatch>
  <url>*/def/*</url>
  <module>other</module>
</dispatch>

When I hit {app engine}/abc/def/test.html I got "default"

Generable answered 12/10, 2018 at 9:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.