如何为微服务构建前端 [英] How to build front end for Microservices

查看:30
本文介绍了如何为微服务构建前端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有十几个微服务.我想知道前端应该去哪里.假设前端是 HTML、Javascript、CSS.一种方法是使其成为由 UI 团队处理的单独服务.所以它可以形成浏览器请求首先进入的API网关.但这似乎与独立自包含服务的想法背道而驰.
浏览器------> API 网关------> 微服务
在我有两个问题
1. 这将如何实施?API 网关将如何为微服务中的 JS 和 CSS 文件以及 HTML 片段提供服务.初始页面加载将如何发生以及从何处加载.
2. 现在我们正在将 HTML 混合到微服务中.但是如果我也想为 Android 和 iOS 应用提供服务呢?谢谢.

Let's say I have a dozen microservices. I am wondering where should the front end go. Let's say front end is HTML, Javascript, CSS. One way is to make it a separate service handled by a UI team. So it can form the API gateway where the request from browser comes in first. But this seems against the idea of independent self contained services.
browser ------> API Gateway ------> Microservices
In this link, they say that Javascript and CSS should be served by microservices. API gateway should serve only the HTML page. THere is a nice diagram showing this >> I have two questions
1. How will this be implemented? How will API gateway serve the JS and CSS files in microservices, and maybe HTML fragments too. How will initial page load happen and from where.
2. Now we are mingling HTML into microservices. But what if I want to serve Android and iOS apps too? THanks.

推荐答案

让我试着直接回答你的 2 个问题,而不讨论任何一种方法.

let me try to answer your 2 questions directly without discussing either approaches.

如果您使用 MV* 模式,则可以使用模块化 Web 应用程序.AngularJS 和 ReactJS 都支持构建模块化应用程序并通过 webpack 或 requireJs 按需加载模块.

Modular Web Apps are possible if you use an MV* pattern. AngularJS and ReactJS both support building modular Apps and load modules on demand via webpack or requireJs.

由于您的 UI 由来自不同微服务的片段组成,您可能需要一个反向代理和一些 CDN 或缓存,以通过将客户端请求管理到单个主机(域)来加速页面加载.

Since your UI is composed of fragments coming from different microservices, you might need a reverse proxy and some CDN or caching to speed up page load by curating client requests to a single host (domain).

原生应用将需要一个 API 层,您可以将微服务整合到单个 API 网关中,甚至可以在移动应用和实际微服务之间开发一个中介 API,以仅公开您实际后端的一个简单子集.

Native Apps will require an API layer and you can curate your microservices into a single API gateway, maybe even develop a mediator API between mobile apps and actual microservices to expose only a simple subset of your actual backend.

这篇关于如何为微服务构建前端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆