Search code examples
google-app-engineapp-engine-modules

appengine safer dispatch.yaml routing to modules / services


This is a basic sense check question as i'm deploying a few new modules:

dispatch.yaml:

application: my-app
# No version required; this does routing independent of version.

dispatch:
  # Default module serves the typical web resources and all static resources.
  - url: "*/favicon.ico"
    module: default

  # Default module serves simple hostname request.
  - url: "simple-sample.appspot.com/"
    module: default

  # Send all mobile traffic to the mobile frontend.
  - url: "*/mobile/*"
    module: mobile-frontend

  # Send all work to the one static backend.
  - url: "*/work/*"
    module: static-backend

Wouldn't it be safer to put "*.com/mobile/*" instead of "*/mobile/*" ? In case other modules could use /mobile/ in their urls somewhere and accidentally get routed to mobile-frontend?

What if I have domain names other than .com e.g. .io?


Solution

  • Yes, it could be considered safer in the way you're looking at it.

    For the additional .io (or other) domains you can add a rule for each of those suffixes:

    - url: "*.com/mobile/*"
      module: mobile-frontend
    - url: "*.io/mobile/*"
      module: mobile-frontend
    

    Side note: you don't actually need to specify the rules for the default module - all requests not matching any rules in the dispatch files are by default routed to the default module, making such rules redundant. You can test this by making a request not matching any of your dispatch.yaml rules and watching the default module's logs.