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. calc()

    width:calc(): cale(a)计算出表达式a的值. e.g: height:cale(100vh-200px):vh,是指CSS中相对长度单位,表示相对视口高度,通常视口长度单位会被分成1 ...

  2. html随笔CSS(*^__^*)

    控制文本显示字数,超过规定的文本长度  x显示... white-space:nowrap;        //规定不能换行 overflow:hidden; text-overflow:ellips ...

  3. 《图解TCP/IP》读书笔记(转)

    reference: https://www.cnblogs.com/edisonchou/p/5987827.html 一.国际惯例:书托 这是一本图文并茂的网络管理技术书籍,旨在让广大读者理解TC ...

  4. unity3d 九宫密码锁

    using UnityEngine;using System.Collections.Generic;using System;using UnityEngine.EventSystems;using ...

  5. SpringMVC学习二

    处理请求 今天学了三种请求,一种是 PathVariable ,一种是 RequestParam ,还有一种是CookieValue,并实现简单rest增删改查 上代码 package com.spr ...

  6. Unity3D使用OpenFileDialog后崩溃

    http://ask.unitymanual.com/question/24922 找了很久,原来是我的dll文件引错了,名字都一样,应该引用unity安装目录下的System.Window.Form

  7. css设置div高度与宽度相等的一种方法

    div.category{ width:33%; padding:33% 0 0; } 1.关键在padding:33% 0 0这句代码,通过设置padding-top与宽度相等(padding使用百 ...

  8. 58-63用ssh远程连接linux系统

    一.注意 在CentOS7.6中,ifconfig来查询IP已经不再适用,要用ip add 二.vim编辑器 编辑:按[i]键可以进入到编辑状态,显示insert这样的字眼就对了 退出:按esc退出编 ...

  9. CNN 参数计算

    CNN 时间计算复杂度与空间复杂度 即,连续个数与参数个数, 每一个连接都意味着一个计算, 每一个参数都意味一个存储单元. 只计算主要部分. CNN局部连接与权值共享 如图所示: 全连接:如左图所示, ...

  10. Python学习笔记第十八周

    目录: 一.JavaScript正则表达式 1.test  2.exec 二.BootStrap  1.响应式  2.图标.字体  3.基本使用 三.Django 1.安装  2.创建目录  3.进入 ...