为子域配置 GAE 应用程序 app.yaml

发布于 2024-10-17 19:07:47 字数 600 浏览 6 评论 0原文

我的域在 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 的内容.pyprojects.pydocs.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

開玄 2024-10-24 19:07:47

这并不完全是您问题的答案,但您可能需要查看 webapp2。它是 Google 网络应用程序的直接替代品,添加了一些真正有用的功能,包括可以按域路由的新路由系统。

有关示例,请查看 routes.py 文件。您需要 DomainRoute

    SUBDOMAIN_RE = '^([^.]+)\.app-id\.appspot\.com

Nick Johnson 写道 不久前关于 webapp2 的一篇博客文章

app = WSGIApplication([ DomainRoute(SUBDOMAIN_RE, [ Route('/foo', 'FooHandler', 'subdomain-thing'), ]), Route('/bar', 'BarHandler', 'normal-thing'), ])

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:

    SUBDOMAIN_RE = '^([^.]+)\.app-id\.appspot\.com

Nick Johnson wrote a blog post about webapp2 a while back.

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.

何止钟意 2024-10-24 19:07:47

最简单的方法可能是导入适当的模块并调用其 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文