I used to do this in GAE Python25 to handle in-app routing of requests to www.example.com and blog.example.com (Notice the difference in subdomains) within the same app, using the code below:
#app.yaml
- url: /
script: main.py
#main.py
applications = {
'www.example.com': webapp.WSGIApplication([('/', MainHandler)],
debug=False),
'blog.example.com': webapp.WSGIApplication([('/', BlogHandler)],
debug=False)
}
def main():
host = os.environ['HTTP_HOST']
if host in applications:
run_wsgi_app(applications[host])
else:
run_wsgi_app(applications['www.example.com'])
if __name__ == '__main__':
main()
But in Python27, the format is something different. It's the following:
#app.yaml
handlers:
- url: /
script: main.app # (instead of main.py)
#main.py
app = webapp2.WSGIApplication([(r'/', MainPage)],debug=True)
How do I achieve the same functionality in Python27 (threadsafe), and route different subdomains to different handlers within the app?
Thanks!
Thanks!
Just use webapp2 domain routing http://webapp-improved.appspot.com/guide/routing.html#domain-and-subdomain-routing
You need todo it on the handler level, something like this:
and in the handler: