2

I have two very simple services set up (in python) on google app engine. I have a site which has been up for a while as the defualt service of my example project, and I just deployed another service, lets call it foo. I have dns forwarding working for the default service, so I can go to example.com (which I own in this hypothetical scenario) and see my default service. I can also go to foo.example.appspot.com and see my foo service, which works at the url.

I have also registered another domain, let's call it foo.com. What I want is for foo.com to use my foo.example.appspot.com service. To make matters trickier, foo.com has a bunch of sub-domains of it's own, so I need x.foo.com to go to my foo service as well (and even x.y.foo.com would be ideal, but if that is hard I can work around that one easily enough by just substituting out another character so it would be x-y.foo.com or something along those lines).

I'm pretty new to web dev (which is honestly a generous description for this simple project), but Iv'e spent a while reading and googling and haven't found a solution to this, so any advice would be helpful. My last resort would be to un-service-ify (if you will) the two services, and just bundle it all up into one big main.py which routes differently depending on the domain, and then point both domains at the default service. The big downside to this is that I already have everything working with services (which seems like a better approach).

I expect to get very few users so scaling isn't really an issue (though it's always interesting to learn about).

EDIT:

attempted to create a dispatch.yaml file to solve this as follows:

dispatch:

  - url: "foo.com"
    module: foo

  - url: "*.foo.com"
    module: foo

but when I run appcfg.py -A <project_id_here> update_dispatch . it says

Error parsing yaml file:
Unable to assign value 'foo.com' to attribute 'url':
invalid url 'foo.com'
  in "./dispatch.yaml", line 3, column 10
stokastic
  • 986
  • 2
  • 7
  • 19

2 Answers2

2

Yes, it should be possible. I didn't actually use 2 different top-level domains, but the development console appears to be ready to accept a second one (I can't actually check as I don't own a 2nd domain). Follow the Adding a custom domain for your application procedure.

Pay special attention to the Wildcard mappings section - since your foo.com domain already has sub-domains in use you can't use wildcards at/above those sub-domains, you'll have to specify the desired subdomains.

The procedure only maps (sub)domains to the app as a whole, not to individual services/modules. You'll also have to use a dispatch file, to route the specific subdomains to the corresponding modules/services. You can find examples here: https://stackoverflow.com/a/32103486/4495081 and https://stackoverflow.com/a/34111170/4495081 (the last one has rules to allow the module to work on the custom domain, on appspot.com and on the local development server).

Community
  • 1
  • 1
Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • Thanks for the tip, dispatch files look like what I want, but I couldn't set up the mappings I wanted (see my edit above). I also tried using `"foo.com/"` and `"foo.com/*"`, all gave the same error message. Any thoughts? EDIT: sorry hold on a sec, I think the second link may have what I need – stokastic Nov 22 '16 at 20:42
  • nope, I can't find an example routing a second entire domain `foo.com` to a service – stokastic Nov 22 '16 at 20:48
2

I got it to work following The links in the answer. My dispatch file wound up looking like this:

dispatch:

  - url: "foo.com/*"
    module: foo

  - url: "*.foo.com/*"
    module: foo
stokastic
  • 986
  • 2
  • 7
  • 19