user1013967
user1013967

Reputation: 1

How to set a subdomain as 'sub.domain.appspot.com' on google app engine?

I know how to set up an app on google app engine as myapp.appspot.com, but I hope to use a.myapp.appspot.com and b.myall.appspot.com for different interfaces of the same app. As google instruction said, this is supported:

appspot.com domains also support subdomains of the form subdomain.your_app_id.appspot.com, where subdomain can be any string allowed in one part of a domain name (not .). Requests sent to any subdomain in this way are routed to your application.

From https://developers.google.com/appengine/docs/python/runtime

But I cannot figure it out how to set up. Has anyone ever created subdomain on appspot?

Upvotes: 0

Views: 2754

Answers (2)

Iceberg
Iceberg

Reputation: 3332

You can take advantage of the SERVICE_ID-dot- notion:

https://SERVICE_ID-dot-PROJECT_ID.REGION_ID.r.appspot.com
https://myall.appspot.com/

https://a-dot-myall.appspot.com/
https://b-dot-myall.appspot.com/

Here, requests with a-dot-myall.appspot.com will be routed to a service named a.
But if the service named a doesn't exist, then request will be routed to myall.appspot.com, which is called soft route.
So you can forge any url with the myall.appspot.com and make routing decision after you received the request in your app even if the service doesn't exist. Actually we've done this with regular expression server_name in nginx.

soft routing explanation

Upvotes: 0

R Samuel Klatchko
R Samuel Klatchko

Reputation: 76541

You don't have to do anything to set that up. It just works.

That said, to implement different interfaces, you need to detect the hostname the caller used. You can get this in HTTP_HOST. HTTP_HOST will have the full name (i.e. "a.myapp.appspot.com" or "b.myapp.appspot.com").

UPDATE: the answer no longer applies if using HTTPS, from Routing via URL:

Note: Google recommends using the HTTPS protocol to send requests to your app. Google does not issue SSL certificates for double-wildcard domains hosted at appspot.com. Therefore with HTTPS you must use the string "-dot-" instead of "." to separate subdomains, as shown in the examples below. You can use a simple "." with your own custom domain or with HTTP addresses.

Upvotes: 5

Related Questions