首页 > node.js > 我应该如何在Google App Engine中构建API和前端应用程序?

我应该如何在Google App Engine中构建API和前端应用程序? (how should I architecture an API and front app in Google App Engine?)

问题

我正在开发我的第一个部署到GAE的node.js应用程序。

它将被组织为API服务和使用Next.js开发的前端Web应用程序

我正在看这个架构,虽然我将应用程序分成两个存储库,但我可以使用一个合并的repo来创建两个不同的微服务:

https://medium.com/this-dot-labs/node-js-microservices-on-google-app-engine-b1193497fb4b

对我来说,似乎过度工作创建了一个新的仓库来合并它们并进行部署(它是否打破了微服务的基本思想之一来进行隔离部署?)

我不得不劝阻这个,因为我们需要在某些部分使用SEO,我们应该使用Next.js(或类似的):

https://cloud.google.com/storage/docs/hosting-static-website

我一直在努力的另一个想法是......为前端创建不同的GAE项目,并独立部署API。对我来说,它似乎是最好的选择,但我想知道你作为GAE专家的意见。

我应该使用哪一个?

谢谢!

解决方法

GAE并不关心如何将代码部署到映射到一个或多个VCS存储库(或根本没有存储库)的服务中。这完全取决于你。

使用单个存储库,您可能会遇到从CI / CD管道部署的困难 - 例如,当仅更改另一个服务时,不必要地部署到一个服务。

许多例子都集中在应用程序而不是服务上,但这些只不过是那些应用程序的默认服务。我个人喜欢将不同服务的代码保存在不同的目录中,看看在Google App Engine应用程序中的默认服务/模块中捕获的图像是否是文件夹结构方面的非默认服务?(它不再出现在更新的文档页面上)。这也允许轻松映射到多个独立的VCS存储库

对于多个项目与多个服务,这可能有所帮助:在GAE项目/应用程序级别与服务/模块级别实施CI / CD环境的优势?

您提到的静态网站链接不是GAE的一部分,它是GCS的一部分- 一种不同的GCP产品。它可以单独使用 - 对于静态网站,但可能很难/不可能:

  • 在其上运行的服务与在GAE上运行的服务之间进行通信 - 如果您需要
  • 使2个服务显示为一个(例如,在相同的自定义域名下服务)

问题

I'm developing my first node.js app deploying to GAE.

It'll be organized as an API service and a front-end web app developed with Next.js

I'm looking at this architecture, and, although I have the app separated in two repositories I could have one merged repo to create two different microservices:

https://medium.com/this-dot-labs/node-js-microservices-on-google-app-engine-b1193497fb4b

For me, it seems overwork creating a new repo to merge them and deploy (doesn't it break one of the basic ideas of microservices to make isolated deploys?)

I have to discourage this because we need SEO in some of the parts, and We should use Next.js (or similar):

https://cloud.google.com/storage/docs/hosting-static-website

Another idea I've been working on is... create different GAE projects for front and API to deploy independently. For me, it seems like the best option, but I would like to know your opinion as GAE experts.

Which one should I use?

Thanks!

解决方法

GAE doesn't care how is the code to be deployed into the services mapped to one or more VCS repositories (or no repositories at all). That's entirely up to you.

With a single repository you may encounter difficulties deploying from CI/CD pipelines - for example unnecessary deployments to one service when only the other one is changed.

Many examples out there focus on applications rather than services, but those are nothing more than the default services of those applications. Personally I like keeping the code for different services in separate directories, see the image captured in Can a default service/module in a Google App Engine app be a sibling of a non-default one in terms of folder structure? (it's no longer present on the updated documentation page). This also allows for easy mapping to multiple, separate VCS repositories

As for multiple projects vs multiple services, this might be of help: Advantages of implementing CI/CD environments at GAE project/app level vs service/module level?

The static website link you mentioned isn't part of GAE, it's part of GCS - a different GCP product. It's fine to use by itself - for a static website, but it might be difficult/impossible to:

  • communicate between a service running on it and one running on GAE - if you need that
  • make the 2 services appear as one (for example serve under the same custom domain name)
相似信息