gpt4 book ai didi

node.js - 谷歌应用引擎 Node.js : Deploying API and WepApp

转载 作者:太空宇宙 更新时间:2023-11-04 00:31:57 26 4
gpt4 key购买 nike

我是 GoogleCloud 新手。我已按照教程(针对 Node.js)执行以下步骤:

  1. 构建我自己的 My-Hello-World 网络应用
  2. 部署到 AppEngine
  3. 它工作正常,如 https://My-Hello-World.appspot.com

  4. 构建我自己的 EndPoints API,项目 ID 为 My-Hello-World

  5. 部署到 AppEngine
  6. 它也可以很好地用作 https://My-Hello-World.appspot.com/api/test/ *

我的问题是,当我部署 EndPoints API 时,我的 My-Hello-World.appspot.com 不再作为 Web 应用程序运行,而是作为 API 进行响应。如何配置以使我的项目在部署到 AppEngine 时同时针对 webapp 和 api 运行?

https://My-Hello-World.appspot.com --> 作为 webapp 运行

https://My-Hello-World.appspot.com/api/test/ * --> 作为 api 运行

谢谢。

最佳答案

所以假设

  • 您的 Endpoints API 和 Web 应用位于同一个 GCP 项目中
  • 每个都有自己的 app.yaml

您可以将它们部署到同一项目的应用引擎,并让它们作为单独的服务一起运行。您需要做的就是在 app.yaml

中添加服务标签
service: api
runtime: nodejs
env: flex

env_variables:
NODE_ENV : staging

这就是我部署到登台的 ExpressJS RestAPI 的样子。

您可以保持网络应用的 app.yaml 不变,因为它将用作默认服务。

然后您就可以访问

  • 网络应用程序
    • https ==> my-hello-world.appspot.com
    • http ==> my-hello-world.appspot.com
  • API
    • https ==> api-dot-my-hello-world.appspot.com
    • http ==> api.my-hello-world.appspot.com
<小时/>

引用

关于node.js - 谷歌应用引擎 Node.js : Deploying API and WepApp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40645566/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com