GAE检测本地主机或appspot的运行地点 [英] GAE detect running place at localhost or appspot

查看:145
本文介绍了GAE检测本地主机或appspot的运行地点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有GAE应用程序。它使用Oauth 2.0协议。我目前使用Java库。
目前,我手动切换重定向URL。



当我在本地主机上测试时,我使用 localhost:8888 / oauth2callback
当我部署应用程序时,我设置了 example.appspot.com/oauth2callback。



因此,如果应用程序在本地主机上运行或部署,我该如何检测?

解决方案

,您可以执行以下操作



您可以检查系统属性 com.google.appengine.runtime.environment 的值,以确定它是生产还是开发。



示例代码来自文档:

  if(SystemProperty .environment.value()== 
SystemProperty.Environment.Value.Production){
//该应用程序正在App Engine上运行...
}


$ b

等。



在Py请仔细阅读以下文档片段:




  • SERVER_SOFTWARE:在开发Web服务器中,此值为Development / XY,其中XY是运行时的版本。在App Engine上运行时,此值为Google App Engine / X.Y.Z。


I have GAE Application. It uses Oauth 2.0 protocol. I use Java library at the moment. At the moment, I manually switch the redirect URL.

When I'm testing on localhost I use localhost:8888/oauth2callback And when I deploy app, I set example.appspot.com/oauth2callback.

So how can I detect, if the app is running on the localhost or is deployed ?

解决方案

As per the documentation, you can do the following

You can check the value of the System property com.google.appengine.runtime.environment to determine if it is "Production" or "Development".

Sample code from docs:

if (SystemProperty.environment.value() ==
SystemProperty.Environment.Value.Production) {
// The app is running on App Engine...
}

and so on.

On the Python side of things, check out the following documentation snippet:

  • SERVER_SOFTWARE: In the development web server, this value is "Development/X.Y" where "X.Y" is the version of the runtime. When running on App Engine, this value is "Google App Engine/X.Y.Z".

这篇关于GAE检测本地主机或appspot的运行地点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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