有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java GAE检测localhost或appspot上的运行位置

我有GAE申请表。它使用OAuth2.0协议。我现在使用Java库。 目前,我手动切换重定向URL

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

那么,我如何检测应用程序是在本地主机上运行还是已部署


共 (2) 个答案

  1. # 1 楼答案

    您可以使用oAuthService方法来检测本地主机环境

    OAuth for Java Overview

    [...] On the local development server, oauth.getCurrentUser() always returns a User object with email set to "example@example.com" and user ID set to 0 regardless of whether or not a valid OAuth request was made. [...]

  2. # 2 楼答案

    根据documentation,您可以执行以下操作

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

    文档中的示例代码:

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

    等等

    在Python方面,请查看以下documentation代码段:

    • 服务器软件:在开发web服务器中,此值为“development/X.Y”,其中“X.Y”是运行时的版本。在App Engine上运行时,此值为“Google App Engine/X.Y.Z”