App Engine - subdomain pointing to particular service

1.1k views Asked by At

I have two subdomains registered in my App Engine application:

  • service-a.my-app.com
  • service-b.my-app.com

I have added all the records (CNAME, A) on the server.

I have three services in my GAE:

  • default
  • service-a
  • service-b

And I want each subdomain to point to the correct service. However, each time I access them, only the default service is used.

Side note: the GAE is running a flexible environment for laravel 5.4 and my dispatch.yaml (located in default service is as follows:

dispatch:
-url: "service-a.my-app.com/*"
 service: service-a
-url: "service-b.my-app.com/*"
 service: service-b
3

There are 3 answers

0
Dan Cornilescu On

Please note that dispatch.yaml is an app-level configuration, not a service-level one and occasionally updating the service containing it doesn't automatically update the app-level configs.

You should use the specific deployment commands for dispatch.yaml, executed from the directory containing the file:

  • gcloud app deploy dispatch.yaml if you're using the Cloud SDK
  • appcfg.py update_dispatch . if you're still using the GAE SDK

See also dispatch.yaml not getting updated.

The same is true for other app-level .yaml config files as well, which is probably one reason for each having its own update/deploy command (and also to allow deploying them independently of any particular app service. Somehow related: Why do I need to deploy a "default" app before I can deploy multiple services in GCP?

1
jrfoehn On

Actually the answer was really easy: You just need to map a wildcard subdomain and GAE would the use the service corresponding to the prefix.

0
deepakssn On

This worked for me. Hope this helps someone.

GAE Standard: I have an angular project which will load for any subdomain except one subdomain "api". The backend is written in Go and all services are under a service named "api"

STEP1: Setting local env

Angular project has the following app.yaml

runtime: python27
api_version: 1
instance_class: F1
handlers:
- url: /
  static_files: default/index.html
  upload: default/index.html
- url: /
  static_dir: default 

My service.yaml file resides in a separate directory and has the following

runtime: go
api_version: go1
instance_class: F1
service: api
handlers:
- url: /.*
  script: _go_app
  secure: always

My dispatch.yaml has the following

dispatch:
- url: "api.MYDOMAINNAME.com/*"
  service: api
//Add more subdomain : services mapping here

I deployed all these files using gcloud app deploy command

Step 2 - Configure Custom domains in GAE.

In GAE Console, goto Project Settings > Custom Domains

  1. Add your domain
  2. Verify your domainusing one of the methods provided by Google.
  3. Update CNAME, A and AAA records in your domain service provider's DNS Settings

Step 3 - Configure Sub Domain

Add a subdomain api.MYDOMAINNAME.com

Add the CNAME in your domain service provider's settings. // add more subdomains if required

Add a Wildcard subdomain *.MYDOMAINNAME.com

Add the CNAME in your domain service provider's settings to redirect * to google.

Finally:

Wait for few minutes for the settings to be applied.

Now your application will redirect MYDOMAINNAME.com, www.MYDOMAINNAME.com , *.MYDOMAINNAME.com to the Angular code

and api.MYDOMAINNAME.com to your api service