Configure GAE application app.yaml for subdomains
I have some subdomains with my domain on GAE. They are, for example, blog.mysite.com, projects.mysite.com and docs.mysite.com. As it is configured now, they all are processed with such settings in main.py
:
def main():
applications = {
'blog.mysite.com': webapp.WSGIApplication([('/', BlogHandler)]),
'projects.mysite.com': webapp.WSGIApplication([('/', ProjectsHandler)]),
'docs.mysite.com': webapp.WSGIApplicatio开发者_StackOverflown([('/', DocsHandler)]),
}
util.run_wsgi_app(applications[os.environ['HTTP_HOST']])
How can I separate these sub-applications to be processed by different modules, so I would have something like blog.py
, projects.py
and docs.py
?
Thanks!
This is not exactly an answer to your question but you may want to look into webapp2. It is a drop-in replacement for Google's webapp that adds some really useful features, including a new routing system that can route by domain.
Check out the routes.py file for examples. You'd want DomainRoute
:
SUBDOMAIN_RE = '^([^.]+)\.app-id\.appspot\.com$'
app = WSGIApplication([
DomainRoute(SUBDOMAIN_RE, [
Route('/foo', 'FooHandler', 'subdomain-thing'),
]),
Route('/bar', 'BarHandler', 'normal-thing'),
])
Nick Johnson wrote a blog post about webapp2 a while back.
Probably the easiest way would be to import the appropriate module and call its main()
function, and do all of the creation of WSGI applications within the separate modules rather than in main.py. (My own microframework does all of this routing within the WSGI Application itself, which gets kind of ugly to the point that I'm rethinking my choice to stick with basically extended webapp-style routing.)
Your title mentions app.yaml; you want to just configure all of your requests to go to main.py and do the dispatching there, since the current runtime doesn't let you do host mapping in app.yaml at all (although there is an open issue requesting this that you could star). This unfortunately means you're left with a choice of not using static handlers or having the same static content URLs on all of your subdomains.
精彩评论