为子域配置 GAE 应用程序 app.yaml
我的域在 GAE 上有一些子域。例如,它们是 blog.mysite.com、projects.mysite.com 和 docs.mysite.com。按照现在的配置,它们都在 main.py
中使用这样的设置进行处理:
def main():
applications = {
'blog.mysite.com': webapp.WSGIApplication([('/', BlogHandler)]),
'projects.mysite.com': webapp.WSGIApplication([('/', ProjectsHandler)]),
'docs.mysite.com': webapp.WSGIApplication([('/', DocsHandler)]),
}
util.run_wsgi_app(applications[os.environ['HTTP_HOST']])
如何将这些子应用程序分开以由不同的模块处理,所以我会有类似 blog 的内容.py
、projects.py
和 docs.py
? 谢谢!
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.WSGIApplication([('/', 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这并不完全是您问题的答案,但您可能需要查看 webapp2。它是 Google 网络应用程序的直接替代品,添加了一些真正有用的功能,包括可以按域路由的新路由系统。
有关示例,请查看 routes.py 文件。您需要
DomainRoute
:Nick Johnson 写道 不久前关于 webapp2 的一篇博客文章。
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
:Nick Johnson wrote a blog post about webapp2 a while back.
最简单的方法可能是导入适当的模块并调用其 main() 函数,并在单独的模块中而不是在 main.py 中完成 WSGI 应用程序的所有创建。 (我自己的微框架在 WSGI 应用程序本身内完成所有这些路由,这有点难看,以至于我正在重新考虑我的选择是否坚持使用基本扩展的 webapp 样式路由。)
您的标题提到了 app.yaml;您只想将所有请求配置为转到 main.py 并在那里进行调度,因为当前运行时根本不允许您在 app.yaml 中进行主机映射(尽管有一个 未决问题请求您加星标)。不幸的是,这意味着您只能选择不使用静态处理程序或在所有子域上使用相同的静态内容 URL。
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.