【问题标题】:How to set up an endpoint on Cloud Shell (Node.js)如何在 Cloud Shell (Node.js) 上设置端点
【发布时间】:2018-02-07 15:08:13
【问题描述】:

在过去一周左右的时间里,我一直在学习 Node.js,我想在我的 Google Cloud 帐户上设置一些端点。我一直在用它来学习和测试,它非常有用。但是,我想要这些端点的 url。

目前,我只想运行下面的代码,它给我的网址是:

https://8080-dot-3465512-dot-devshell.appspot.com/

这显然不是正确的,尽管它确实返回了 'hello'。

有没有办法让我找到主机 URL,以便我可以将其用作端点?

var express = require('express');

var app = express();

app.get('/', function(req,res){
    res.send("hello");
});

console.log("begin");

app.listen(8080);

【问题讨论】:

  • 你想达到什么目的?你想给你的端点一个特定的域,例如,www.myapp.com
  • 这是一个关于如何开始使用Cloud Endpoints for NodeJs 的教程。这是你想要的吗?请回答

标签: node.js google-app-engine express google-cloud-endpoints


【解决方案1】:

当您在 Cloud Shell 本地部署 Node 项目并使用 Web Preview button 时,通常会收到类似的 URL (_https://8080-dot-3465512-dot-devshell.appspot.com/_)。

如果您想使用 Google Cloud Endpoints 设置 NodeJS 端点,您必须关注 this steps

  1. 设置 Cloud Platform 项目、安装所需软件并创建 App Engine 应用。见Before you begin

  2. 下载示例代码:

git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples

然后cd nodejs-docs-samples/endpoints/getting-started

  1. 配置openapi-appengine.yaml文件,用于配置Endpoints的内容:

    swagger: "2.0"
    info:
      description: "A simple Google Cloud Endpoints API example."
      title: "Endpoints Example"
      version: "1.0.0"
    host: "YOUR-PROJECT-ID.appspot.com"
    

    看到你必须在最后一行替换:YOUR-PROJECT-ID...

  2. 使用以下命令部署 Endpoints 配置以创建 Cloud Endpoints 服务:gcloud endpoints services deploy openapi-appengine.yaml

  3. 创建一个后端来提供 API 并部署 API。 See Deploying the API backend.

  4. 向 API 发送请求。 See Sending a request to the API.

  5. 跟踪 API 活动。 See Tracking API activity

8.避免对您的 Google Cloud Platform 帐户产生费用。请参阅清理。

我试图对其进行总结,但有时您必须点击链接。希望这会有所帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-01
    • 2018-12-16
    • 2021-02-17
    • 2021-09-24
    • 1970-01-01
    • 2017-09-22
    • 2021-08-24
    • 1970-01-01
    相关资源
    最近更新 更多