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

说明

测试代码很简单,实际可以支持好多强大的功能,具体的可以参考tailor 的examples 目录

参考资料

https://www.mosaic9.org/
https://github.com/zalando/tailor
https://github.com/rongfengliang/tailor-skipper-docker-compose

 
 
 
 

tailor+ skipper 实现micro-frontends 简单试用的更多相关文章

  1. Micro Frontends

    Micro Frontends - extending the microservice idea to frontend development https://micro-frontends.or ...

  2. Micro Frontends 微前端

    Micro Frontends https://martinfowler.com/articles/micro-frontends.html Integration approaches Server ...

  3. Micro Frontends & microservices

    Micro Frontends & microservices https://micro-frontends.org/ https://github.com/neuland/micro-fr ...

  4. skipper http router 简单试用

    说明: 使用源码编译,注意需要FQ,以及golang版本的问题,新版使用的是go mod 进行依赖管理 环境准备 clone 代码 git clone https://github.com/zalan ...

  5. jQuery无刷新上传之uploadify简单试用

    先简单的侃两句:貌似已经有两个月的时间没有写过文章了,不过仍会像以前那样每天至少有一至两个小时是泡在园子里看各位大神的文章.前些天在研究“ajax无刷新上传”方面的一些插件,用SWFUpload实现了 ...

  6. Micro:Bit手柄试用之一MagicPad (解决蓝牙与gamePad包共存)

    前言 原创文章,转载引用务必注明链接.由于本人初次接触Micro:Bit,水平有限,如有疏漏,欢迎指正. Micro:Bit真好玩! DFRobot的论坛相关资料算是国内比较丰富的了,个人感觉MB比A ...

  7. cloudevents js sdk 简单试用

    cloudevents 目前官方提供了不同语言的sdk,以下是js 的简单学习试用,从目前来说更新不是很好 clone 代码 git clone https://github.com/cloudeve ...

  8. podium micro-frontends 简单试用

    以下是一个简单的podium 试用,包含了layout 以及podlets,使用docker 运行 podium 主要包含了两大部分 podlets 片段服务 layouts 片段组合服务 环境准备 ...

  9. Visual Studio Code 的简单试用体验

    首先对Visual Studio Code做一个大概的介绍.首先明确一下,这个Visual Studio Code(以下简称 vscode)是一个带GUI的代码编辑器,也就是只能完成简单的代码编辑功能 ...

随机推荐

  1. java.lang.ClassCastException: android.os.BinderProxy cannot be cast to com.test.Test

    由于我在第二个Activity中指定了进程名字,但是服务却没有指定进程名(默认跟主入口一个进程)所以报错. 网上找到的是 服务 和绑定服务的客户端必须在同一个application或者进程中,所以Ma ...

  2. mvc4使用百度ueditor编辑器

    前言 配置.net mvc4项目使用ueditor编辑器,在配置过程中遇见了好几个问题,以此来记录解决办法.编辑器可以到http://ueditor.baidu.com/website/downloa ...

  3. request 的下载文件

    前言:Content-Type类型为octets/stream,这种一般是文件类型了,比如有时候需要导出excel数据,下载excel这种场景如何用python来实现呢? 1.点击导出按钮 2.代码实 ...

  4. L295 how to turn down a job but keep a good relationship with the hiring manager

    Let’s say you’re on the hunt for a new job. Three interviews in, you realize it’s not the place for ...

  5. Python 基础字典的增删改查

    # 字典相关的代码## 1.字典的特性:a 字典的无序性: b 数据关联性强 C 键键值对 唯一一个映射数据类型# 字典的键必修二是可哈希的(不可变的数据类型:,字符串,数字的,布尔值,元祖)# 并且 ...

  6. 如何在Power BI和Tableau之间进行选择?

    作者:Mike Gallucci 如今,当谈到商业智能(BI)分析软件时,有两个主要的行业领导者 - 微软的Power BI和Tableau.根据分析和业务平台的2018年Gartner Magic ...

  7. C++中vector容器的常用操作方法实例总结

    C++中vector容器的常用操作方法实例总结 参考 1. C++中vector容器的常用操作方法实例总结: 完

  8. Project篇:项目1

    项目: 步骤: (1)布置项目 (2)独立完成项目设计 (3)项目框架讲解 (4)独立完成项目功能编写 (5)项目讲解 项目内容介绍: 项目开发流程: 需求分析------>概要设计------ ...

  9. [LeetCode&Python] Problem 242. Valid Anagram

    Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Input: ...

  10. P3084 [USACO13OPEN]照片Photo (dp+单调队列优化)

    题目链接:传送门 题目: 题目描述 Farmer John has decided to assemble a panoramic photo of a lineup of his N cows ( ...