GVKun编程网logo

使用Google App Engine轻松(google appengine怎么用)

18

在这篇文章中,我们将为您详细介绍使用GoogleAppEngine轻松的内容,并且讨论关于googleappengine怎么用的相关问题。此外,我们还会涉及一些关于GoogleAppEngine和Go

在这篇文章中,我们将为您详细介绍使用Google App Engine轻松的内容,并且讨论关于google appengine怎么用的相关问题。此外,我们还会涉及一些关于Google App Engine 和 Google Compute Engine 有什么区别?、Google Cloud函数调用托管在Google App Engine上的URL、Google+登录-服务器端流程-Python-Google App Engine、google-app-engine – Appengine – 使用https的本地开发服务器的知识,以帮助您更全面地了解这个主题。

本文目录一览:

使用Google App Engine轻松(google appengine怎么用)

使用Google App Engine轻松(google appengine怎么用)

我有一个可以正常工作的Rest Web服务,它使用JBoss Resteasy,但是当我尝试移植它以使用GAE时,执行时出现此错误:

java.lang.ClassNotFoundException: org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap

答案1

小编典典

我在GAE上成功使用resteasy。正如csturtz所述,请确保您的项目具有resteasy依赖性。

如果您使用Maven,应该是这样的:

<dependency>    <groupId>org.jboss.resteasy</groupId>    <artifactId>resteasy-jaxrs</artifactId>    <version>${resteasy.version}</version></dependency>

并且您还可以选择使用:

<dependency>    <groupId>org.jboss.resteasy</groupId>    <artifactId>resteasy-hibernatevalidator-provider</artifactId>    <version>${resteasy.version}</version></dependency><dependency>    <groupId>org.jboss.resteasy</groupId>    <artifactId>resteasy-jackson-provider</artifactId>    <version>${resteasy.version}</version></dependency>

Google App Engine 和 Google Compute Engine 有什么区别?

Google App Engine 和 Google Compute Engine 有什么区别?

我想知道 App Engine 和 Compute Engine 之间的区别是什么。任何人都可以向我解释其中的区别吗?

答案1

小编典典

App Engine 是一种平台即服务。这意味着您只需部署代码,平台会为您完成所有其他工作。例如,如果您的应用非常成功,App Engine
将自动创建更多实例来处理增加的数量。

阅读有关 App Engine
的更多信息

Compute Engine 是一种基础架构即服务。您必须创建和配置自己的虚拟机实例。它为您提供了更大的灵活性,并且通常比 App Engine
成本低得多。缺点是您必须自己管理应用程序和虚拟机。

详细了解 Compute Engine

如有必要,您可以混合使用 App Engine 和 Compute Engine。它们都可以很好地与Google Cloud
Platform的其他部分配合使用。

编辑(2016 年 5 月):

另一个重要的区别:如果没有请求进入,在 App Engine
上运行的项目可以缩减到零实例。这在开发阶段非常有用,因为您可以持续数周而不会超过实例小时的慷慨免费配额。灵活的运行时(即“托管虚拟机”)需要至少一个实例来持续运行。

编辑(2017 年 4 月):

Cloud Functions (目前处于测试阶段)在抽象方面比 App Engine 更上一层楼 -
没有实例!它允许开发人员部署一小段代码来执行以响应不同的事件,其中可能包括 HTTP 请求、云存储中的更改等。

与 App Engine 的最大区别在于函数按每 100 毫秒计费,而 App Engine 的实例仅在 15 分钟不活动后才会关闭。另一个优点是
Cloud Functions 立即执行,而对 App Engine 的调用可能需要一个新实例 -
并且冷启动一个新实例可能需要几秒钟或更长时间(取决于运行时和您的代码)。

这使得 Cloud Functions 非常适合 (a) 罕见调用 - 无需让实例保持活动状态以防万一发生某些事情,(b)
快速变化的负载,其中实例经常旋转和关闭,可能还有更多用例。

阅读有关云函数的更多信息

Google Cloud函数调用托管在Google App Engine上的URL

Google Cloud函数调用托管在Google App Engine上的URL

我有一个firebase数据库,我希望创建一个云函数,该函数将在将子节点添加到父节点时触发,该函数应使用在父节点中添加的子节点的参数来调用url。

该网址将称为Google App Engine中托管的NodeJS Express应用程序。

如果可能的话,我该怎么办?

答案1

小编典典

您可以使用node.js 请求库来执行此操作。

由于在Cloud Function内部,执行异步任务时必须返回Promise,因此需要使用接口包装来处理请求,例如request-
promise。

您可以按照以下方式进行操作:

.....var rp = require(''request-promise'');.....exports.yourCloudFucntion = functions.database.ref(''/parent/{childId}'')    .onCreate((snapshot, context) => {      // Grab the current value of what was written to the Realtime Database.      const createdData = snapshot.val();      var options = {          url: ''https://.......'',          method: ''POST'',          body: ....          json: true // Automatically stringifies the body to JSON      };      return rp(options);    });

如果要将参数传递给所调用的HTTP(S)服务/端点,则可以通过请求的正文来完成,例如:

      .....      const createdData = snapshot.val();      var options = {          url: ''https://.......'',          method: ''POST'',          body: {              some: createdData.someFieldName          },          json: true // Automatically stringifies the body to JSON      };      .....

或通过一些查询字符串键值对,例如:

      .....      const createdData = snapshot.val();      const queryStringObject = {          some: createdData.someFieldName,         another: createdData.anotherFieldName      };      var options = {          url: ''https://.......'',          method: ''POST'',          qs: queryStringObject      };      .....

Google+登录-服务器端流程-Python-Google App Engine

Google+登录-服务器端流程-Python-Google App Engine

我正在使用Flask在Google App
Engine上构建应用程序。我正在从https://developers.google.com/+/web/signin/server-side-
flow中描述的服务器端流程实现Google+登录。切换到App Engine之前,我的工作流程非常相似。从那时起,也许我引入了一个错误。也许这与我在App
Engine中的实施有关。

我相信Google登录流程重定向到的网址应具有GET参数集“ gplus_id”,但是,我没有收到此参数。

我有一个通过以下方式创建的登录按钮:

(function() {  var po = document.createElement(''script'');  po.type = ''text/javascript''; po.async = true;  po.src = ''https://plus.google.com/js/client:plusone.js?onload=render'';  var s = document.getElementsByTagName(''script'')[0];  s.parentNode.insertBefore(po, s);})();function render() {  gapi.signin.render(''gplusBtn'', {    ''callback'': ''onSignInCallback'',    ''clientid'': ''{{ CLIENT_ID }}'',    ''cookiepolicy'': ''single_host_origin'',    ''requestvisibleactions'': ''http://schemas.google.com/AddActivity'',    ''scope'': ''https://www.googleapis.com/auth/plus.login'',    ''accesstype'': ''offline'',    ''width'': ''iconOnly''  });}

在页面的javascript代码中,我具有启动流程的功能:

var helper = (function() {  var authResult = undefined;  return {    onSignInCallback: function(authResult) {      if (authResult[''access_token'']) {        // The user is signed in        this.authResult = authResult;        helper.connectServer();      } else if (authResult[''error'']) {        // There was an error, which means the user is not signed in.        // As an example, you can troubleshoot by writing to the console:        console.log(''GPlus: There was an error: '' + authResult[''error'']);      }      console.log(''authResult'', authResult);    },    connectServer: function() {      $.ajax({        type: ''POST'',        url: window.location.protocol + ''//'' + window.location.host + ''/connect?state={{ STATE }}'',        contentType: ''application/octet-stream; charset=utf-8'',        success: function(result) {          // After we load the Google+ API, send login data.          gapi.client.load(''plus'',''v1'',helper.otherLogin);        },        processData: false,        data: this.authResult.code,        error: function(e) {          console.log("connectServer: error: ", e);        }      });    }  }})();/** * Calls the helper method that handles the authentication flow. * * @param {Object} authResult An Object which contains the access token and *   other authentication information. */function onSignInCallback(authResult) {  helper.onSignInCallback(authResult);}

这将在“ /
connect”处启动流程(请参见以上文档中引用的步骤8 ):

@app.route(''/connect'', methods=[''GET'', ''POST''])def connect():    # Ensure that this is no request forgery going on, and that the user    # sending us this connect request is the user that was supposed to.    if request.args.get(''state'', '''') != session.get(''state'', ''''):        response = make_response(json.dumps(''Invalid state parameter.''), 401)        response.headers[''Content-Type''] = ''application/json''        return response    # Normally the state would be a one-time use token, however in our    # simple case, we want a user to be able to connect and disconnect    # without reloading the page.  Thus, for demonstration, we don''t    # implement this best practice.    session.pop(''state'')    gplus_id = request.args.get(''gplus_id'')    code = request.data    try:        # Upgrade the authorization code into a credentials object        oauth_flow = client.flow_from_clientsecrets(''client_secrets.json'', scope='''')        oauth_flow.redirect_uri = ''postmessage''        credentials = oauth_flow.step2_exchange(code)    except client.FlowExchangeError:        app.logger.debug("connect: Failed to upgrade the authorization code")        response = make_response(            json.dumps(''Failed to upgrade the authorization code.''), 401)        response.headers[''Content-Type''] = ''application/json''        return response    # Check that the access token is valid.    access_token = credentials.access_token    url = (''https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=%s''           % access_token)    h = httplib2.Http()    result = json.loads(h.request(url, ''GET'')[1])    # If there was an error in the access token info, abort.    if result.get(''error'') is not None:        response = make_response(json.dumps(result.get(''error'')), 500)        response.headers[''Content-Type''] = ''application/json''        return response    # Verify that the access token is used for the intended user.    if result[''user_id''] != gplus_id:        response = make_response(            json.dumps("Token''s user ID doesn''t match given user ID."), 401)        response.headers[''Content-Type''] = ''application/json''        return response    ...

但是,流程在处停止if result[''user_id''] !=gplus_id:,说“令牌的用户ID与给定的用户ID不匹配”。result[''user_id'']是有效的用户ID,但gplus_id没有。

该行gplus_id = request.args.get(''gplus_id'')期望GET args包含“ gplus_id”,但它们仅包含“
state”。我的javascript connectServer函数是否有问题?我应该在其中包括“
gplus_id”吗?当然我当时还不知道。或者是其他东西?

答案1

小编典典

与此问题p类似,我认为这是文档不完整/不是最新/不一致的问题。

凡https://developers.google.com/+/web/signin/server-side-
flow表明,gplus_id将在GET参数被退回,这不是我所用的流量的情况。

我在https://github.com/googleplus/gplus-quickstart-
python/blob/master/signin.py中找到了答案,其中包括以下代码段:

# An ID Token is a cryptographically-signed JSON object encoded in base 64.# Normally, it is critical that you validate an ID Token before you use it,# but since you are communicating directly with Google over an# intermediary-free HTTPS channel and using your Client Secret to# authenticate yourself to Google, you can be confident that the token you# receive really comes from Google and is valid. If your server passes the# ID Token to other components of your app, it is extremely important that# the other components validate the token before using it.gplus_id = credentials.id_token[''sub'']

google-app-engine – Appengine – 使用https的本地开发服务器

google-app-engine – Appengine – 使用https的本地开发服务器

目标:
使用App Engine开发服务器减少开发 – 反馈周期.
对于我的使用,这必须作为公共HTTPS地址提供. App Engine开发服务器仅支持HTTP.

这该怎么做:
使用ngrok将本地开发环境公开为https公开可用地址.

使用从https到http的Nginx反向代理.

这似乎是可能的,但对于我的生活,我没有配置工作.

我在osx上使用App Engine Standard Java.

欢迎其他工作解决方案或想法.当然有办法做到这一点.

最佳答案
我使用Nginx作为我的项目https://debtstracker.io/的自签名证书的代理

这是我的Nginx配置.您还需要将一些yourproject.local记录添加到hosts文件中.

    server {  # This servers dynamic content of DebtsTracker.io project over HTTPS
            listen          443;
            server_name     debtstracker.local;
            ssl                  on;
            ssl_certificate      /etc/ssl/certs/debtstracker-local.crt;
            ssl_certificate_key  /etc/ssl/private/debtstracker-local.key;

            location /app/ {
                    proxy_pass   http://localhost:8100/;
                    proxy_set_header Host $http_host;
            }

            location / {
                    proxy_pass   http://127.0.0.1:8080;
                    proxy_set_header Host $http_host;
            }
    }

第一个位置是GAE devserver,第二个位置是Ionic项目.

这是我用来生成证书的bash文件:

#!/usr/bin/env bash
# https://www.accuweaver.com/2014/09/19/make-chrome-accept-a-self-signed-certificate-on-osx/

# https://gist.github.com/jessedearing/2351836

# Run using "sudo"

echo "Generating an SSL private key to sign your certificate..."
openssl genrsa -des3 -out debtstracker-local.key 1024

echo "Generating a Certificate Signing Request..."
openssl req -new -key debtstracker-local.key -out debtstracker-local.csr

echo "Removing pass-phrase from key (for Nginx)..."
cp debtstracker-local.key debtstracker-local.key.org
openssl rsa -in debtstracker-local.key.org -out debtstracker-local.key
rm debtstracker-local.key.org

echo "Generating certificate..."
openssl x509 -req -days 365 -in debtstracker-local.csr -signkey debtstracker-local.key -out debtstracker-local.crt

echo "copying certificate (debtstracker-local.crt) to /etc/ssl/certs/"
mkdir -p  /etc/ssl/certs
cp debtstracker-local.crt /etc/ssl/certs/

echo "copying key (debtstracker-local.key) to /etc/ssl/private/"
mkdir -p  /etc/ssl/private
cp debtstracker-local.key /etc/ssl/private/

希望这可以帮助.我花了一些时间来设置它.

今天的关于使用Google App Engine轻松google appengine怎么用的分享已经结束,谢谢您的关注,如果想了解更多关于Google App Engine 和 Google Compute Engine 有什么区别?、Google Cloud函数调用托管在Google App Engine上的URL、Google+登录-服务器端流程-Python-Google App Engine、google-app-engine – Appengine – 使用https的本地开发服务器的相关知识,请在本站进行查询。

本文标签: