阻止来自 *.appspot.com 的请求并在 Google App Engine 中强制自定义域 [英] Block requests from *.appspot.com and force custom domain in Google App Engine

查看:15
本文介绍了阻止来自 *.appspot.com 的请求并在 Google App Engine 中强制自定义域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何阻止用户在 example.appspot.com 上访问我的应用程序并强制他们在 example.com 上访问它?我已经在使用 example.com,但我不希望用户能够访问 appspot 域.我正在使用 python.

How can I prevent a user from accessing my app at example.appspot.com and force them to access it at example.com? I already have example.com working, but I don't want users to be able to access the appspot domain. I'm using python.

推荐答案

您可以检查是否 os.environ['HTTP_HOST'].endswith('.appspot.com') -- 如果是,那么您将从 something.appspot.com 提供服务,并且可以发送重定向,或者根据需要以其他方式改变您的行为.

You can check if os.environ['HTTP_HOST'].endswith('.appspot.com') -- if so, then you're serving from something.appspot.com and can send a redirect, or otherwise alter your behavior as desired.

您可以通过各种方式(装饰器、WSGI 中间件、从您的中间基类继承 webapp.RequestHandler [[或您当前使用的任何其他基本处理程序类]] 和方法名称与应用程序级处理程序类中的 get 和 post 不同,以及其他)但我认为这里的关键思想是os.environ 是由应用引擎框架根据 CGI 标准设置的,因此您可以依赖这些标准(同样,WSGI 根据从 os.environ 获取的值构建自己的环境).

You could deploy this check-and-redirect-if-needed (or other behavior alteration of your choice) in any of various ways (decorators, WSGI middleware, inheritance from an intermediate base class of yours that subclasses webapp.RequestHandler [[or whatever other base handler class you're currently using]] and method names different than get and post in your application-level handler classes, and others yet) but I think that the key idea here is that os.environ is set by the app engine framework according to CGI standards and so you can rely on those standards (similarly WSGI builds its own environment based on the values it picks up from os.environ).

这篇关于阻止来自 *.appspot.com 的请求并在 Google App Engine 中强制自定义域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆