Does GAE support me having unlimited subdomains?

2019-06-04 22:52发布

If I want to run my service on google app engine (python), do they all me to create my own custom subdomains easily and without any limit?

For example, my service will run on my custom domain:

www.example.com

For each customer I will create their own custom domain like:

customer1.example.com

I may have 1000's of customers, so this would have to be easily done using an API call or they allow wildcards.

My application will analyze the subdomain and lookup the customer.

This will be a single application that will handle all subdomains.

1条回答
Animai°情兽
2楼-- · 2019-06-04 22:58

Sure, have the wildcard (*) CNAME record of your domain (i.e. *.example.com) point to ghs.googlehosted.com in your DNS panel and all requests to any subdomain of your main domain will go to your app (and make sure this is also reflected on the GAE's Custom Domains Settings Page as shown on the screenshot below):

enter image description here

Then have one of your first webapp2 routes as something similar to:

    # match all subdomains BUT www
    DomainRoute(r'<:(?!www\.)[^.]+>.example.com', [
        Route('/', handler=CustomSubDomainHandler)
    ])

which will match requests to any subdomains but the www one (since you might want to serve your actual app via that one).

And your CustomSubDomainHandler could look simmilar to:

class CustomSubDomainHandler(webapp2.RequestHandler):
    def get(self):
        subdomain = self.request.host.split('.')[0]
        # code to look up the customer by analyzing the `subdomain` goes here...
查看更多
登录 后发表回答