如何在本地测试 AppEngine 中的多个域设置?
在问题在 Google App Engine 中使用子域中,以下代码被建议。
applications = {
'product.example.com': webapp.WSGIApplication([
('/', IndexHandler),
('/(.*)', ProductHandler)]),
'user.example.com': webapp.WSGIApplication([
('/', IndexHandler),
('/(.*)', UserHandler)]),
}
def main():
run_wsgi_app(applications[os.environ['HTTP_HOST']])
if __name__ == '__main__':
main()
我的问题是如何在本地进行测试?当我在本地测试它时,主机是“localhost:8080”,而不是任何域。
In the question Working with subdomain in google app engine, the following code was suggested.
applications = {
'product.example.com': webapp.WSGIApplication([
('/', IndexHandler),
('/(.*)', ProductHandler)]),
'user.example.com': webapp.WSGIApplication([
('/', IndexHandler),
('/(.*)', UserHandler)]),
}
def main():
run_wsgi_app(applications[os.environ['HTTP_HOST']])
if __name__ == '__main__':
main()
My question is how do I test this locally? When I'm testing it locally, the host is "localhost:8080" and not any of the domains.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Hosts 文件中创建两个新条目:
并在默认 Http 端口 80 上运行本地 GAE 应用程序。
如果由于某种原因,您无法在端口 80 上运行 GAE,您可以尝试修改
application.py
以匹配本地端口号,如下所示:或者更好地修改 main 函数像这样(感谢@Nick的评论):
您应该准备好使用以下地址测试您的本地应用程序:
http://product.example.com:8080
http://user.example.com:8080
请记住切换回您的
主机
文件能够到达生产服务器。Create two new entries in your Hosts file:
and run your local GAE application on default Http port 80.
If, for some reason, you can't run GAE on port 80, you could try to modify your
application.py
to match the local port number with something like this:Or even better modifying the main function like this (Thanks to @Nick's comment):
You should be ready to test your local application with the following addresses:
http://product.example.com:8080
http://user.example.com:8080
Remember to switch back your
Hosts
file to be able to reach the Production server.