tailor+ skipper 实现micro-frontends 简单试用
tailor 在Mosaic 框架中扮演fragment 模版layout的处理,后端fragment可以用任何服务编写
tailor 主要就是进行layout的处理。tailor的是类似facebook bigpipe的实现,功能
挺强大的。
说明:测试使用docker-compose 运行
环境准备
- docker-compose 文件
version: "3"
services:
skipper:
image: dalongrong/skipper:latest
ports:
- "9090:9090"
- "9911:9911"
volumes:
- "./router.eskip:/router.eskip"
command: skipper -enable-ratelimits -enable-prometheus-metrics -routes-file /router.eskip
web:
build:
context: ./
dockerfile: Dockerfile
ports:
- "8080:8080"
fragment-a:
build:
context: ./
dockerfile: Dockerfile-fragment-a
ports:
- "8081:8081"
- web dockerfile
web 服务实际上是入口服务,为了简单,使用了docker 运行,实际上就是一个node 项目,使用tailor 进行layout处理
FROM node:9
WORKDIR /app
COPY index.js /app/index.js
COPY templates /app/templates
COPY package.json /app/package.json
RUN yarn
CMD [ "yarn","start"]
index.js 是入口
'use strict';
const http = require('http');
const Tailor = require('node-tailor');
const tailor = new Tailor({
templatesPath: './templates'
});
// Root Server
http
.createServer((req, res) => {
tailor.requestHandler(req, res);
})
.listen(8080, function() {
console.log('Tailor server listening on port 8080');
});
模版定义
templates 目录下,注意需要一个index.html 的文件
<!-- Tailor needs an index.html -->
<h1>dalong demo</h1>
// 此处使用skipper 的router 之后的地址
<fragment primary id="fragment-1" src="http://skipper:9090/fragment-a"></fragment>
- fragment dockerfile
fragment 是具体的代码片段的代码,这个比较简单,就是一个html 页面的输出
FROM node:9
WORKDIR /app
COPY fragment-a/* /app/
EXPOSE 8081
CMD [ "yarn","start" ]
fragment-a/index.js
const http = require('http');
http
.createServer((req, res) => {
res.writeHead(200, {
'Content-Type': 'text/html'
});
res.end('<div>Fragment 1</div>');
})
.listen(8081, function() {
console.log('Fragment Server listening on port 8081');
});
- skipper router 配置
主要是对于路由的添加,同时添加了一些filter 支持gzip 以及cors
root: Path("/") ->setPath("/index")->compress("text/html")-> corsOrigin()
->setResponseHeader("TOKEN","dalongdemo") ->"http://web:8080";
fragment_a: Path("/fragment-a") ->compress("text/html")-> corsOrigin()
->"http://fragment-a:8081";
启动&&测试
- 启动
docker-compose up -d
- 效果
访问http://localhost:9090 可以查看效果,或者http://localhost:8080/index 访问没有使用skipper 的入口

说明
测试代码很简单,实际可以支持好多强大的功能,具体的可以参考tailor 的examples 目录
参考资料
https://www.mosaic9.org/
https://github.com/zalando/tailor
https://github.com/rongfengliang/tailor-skipper-docker-compose
tailor+ skipper 实现micro-frontends 简单试用的更多相关文章
- Micro Frontends
Micro Frontends - extending the microservice idea to frontend development https://micro-frontends.or ...
- Micro Frontends 微前端
Micro Frontends https://martinfowler.com/articles/micro-frontends.html Integration approaches Server ...
- Micro Frontends & microservices
Micro Frontends & microservices https://micro-frontends.org/ https://github.com/neuland/micro-fr ...
- skipper http router 简单试用
说明: 使用源码编译,注意需要FQ,以及golang版本的问题,新版使用的是go mod 进行依赖管理 环境准备 clone 代码 git clone https://github.com/zalan ...
- jQuery无刷新上传之uploadify简单试用
先简单的侃两句:貌似已经有两个月的时间没有写过文章了,不过仍会像以前那样每天至少有一至两个小时是泡在园子里看各位大神的文章.前些天在研究“ajax无刷新上传”方面的一些插件,用SWFUpload实现了 ...
- Micro:Bit手柄试用之一MagicPad (解决蓝牙与gamePad包共存)
前言 原创文章,转载引用务必注明链接.由于本人初次接触Micro:Bit,水平有限,如有疏漏,欢迎指正. Micro:Bit真好玩! DFRobot的论坛相关资料算是国内比较丰富的了,个人感觉MB比A ...
- cloudevents js sdk 简单试用
cloudevents 目前官方提供了不同语言的sdk,以下是js 的简单学习试用,从目前来说更新不是很好 clone 代码 git clone https://github.com/cloudeve ...
- podium micro-frontends 简单试用
以下是一个简单的podium 试用,包含了layout 以及podlets,使用docker 运行 podium 主要包含了两大部分 podlets 片段服务 layouts 片段组合服务 环境准备 ...
- Visual Studio Code 的简单试用体验
首先对Visual Studio Code做一个大概的介绍.首先明确一下,这个Visual Studio Code(以下简称 vscode)是一个带GUI的代码编辑器,也就是只能完成简单的代码编辑功能 ...
随机推荐
- swiftlint 你所要知道的所有!!
swiftin Should the opening brace of a function or control flow statement be on a new line or not ?:) ...
- 2019-03-07-day006-小数据池
01 昨日内容回顾 字典: 映射,{} 键值对的形式存储,容器型数据类型,key 唯一的,可哈希的,value任意数据类型,对象. 3.6之前无序的, 3.6之后,有序的(第一次创建字典的顺序) 特点 ...
- sql order by 结合case when then
SELECT * FROM datav.a_current_per_entry_01 WHERE intime = (SELECT MAX(intime) FROM a_current_per_ent ...
- python day03作业
- Python用户交互
print("开始") # 赋值,把等号右边的内容赋值给左边 s = input() #input("这里是input")# input输入,让用户输入一些内容 ...
- react native 第三方组件
react native 的成功离不开优秀的第三方组件,以下是我见过的一些优秀或者有用的RN第三方组件 按钮 APSL/react-native-button 导航 react-native-simp ...
- [转]自然语言处理中的Attention Model:是什么及为什么
自然语言处理中的Attention Model:是什么及为什么 https://blog.csdn.net/malefactor/article/details/50550211 /* 版权声明:可以 ...
- DS18B20读数错误排除
描述: 同时测试了好几个板子,都接了DS18B20传感器.但,有的板子读取的DS18B20温度值正确,有的读取错误. 原因查找: 以为是有的传感器坏了,但测试后发现并不是. 又以为是DS18B20需要 ...
- Linux 对文件进行加密存放
/********************************************************************** * Linux 对文件进行加密存放 * 说明: * Gi ...
- 使用Git来撤销修改
首先进入一个有Git管理的文件夹下: 当我们在文件编写过程中出现了一个错误怎么办呢?如下: 但是此时你并没有将文件提交缓冲区,你可以去手动打卡文件删除这个错误. 当然你也可以查看一下状态: 发现这个文 ...