以下是一个简单的podium 试用,包含了layout 以及podlets,使用docker 运行
podium 主要包含了两大部分

  • podlets
    片段服务
  • layouts
    片段组合服务

环境准备

  • docker-compose 文件
 
version: '3'
services:
  layout:
     build:
       context: layouts/home
       dockerfile: Dockerfile
     ports:
     - "7000:7000"
  layout-index:
     build:
       context: podlets/indexpage
       dockerfile: Dockerfile
     ports:
     - "7100:7100"
  layout-userlogin:
     build:
       context: podlets/userlogin
       dockerfile: Dockerfile
     ports:
     - "7101:7101"

服务编写

  • podlets/indexpage
    package.json
{
  "name": "indexpage",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "@podium/podlet": "^4.2.0",
    "express": "^4.17.1"
  },
  "scripts": {
    "app":"node index"
  }
}
 

index.js

const express = require("express")
const Podlet = require("@podium/podlet")
const app = express();
const podlet = new Podlet({
    name: 'index', // required
    version: '1.0.0', // required
    pathname: '/', // required
    manifest: '/manifest.json', // optional, defaults to '/manifest.json'
    content: '/', // optional, defaults to '/'
    development: true, // optional, defaults to false
});
app.use(podlet.middleware());
app.get(podlet.content(), (req, res) => {
    res.status(200).podiumSend(`
        <div>
            This is the index podlet's HTML content
        </div>
    `);
});
app.get(podlet.manifest(), (req, res) => {
    res.status(200).send(podlet);
});
app.listen(7100);
 
 

Dockerfile

FROM node:alpine
LABEL AUTHOR="1141591465@qq.com"
WORKDIR /app
COPY . /app
RUN yarn
EXPOSE 7100
RUN yarn
CMD [ "yarn", "app"]
 
 
  • podlets/userlogin
    package.json
 
{
  "dependencies": {
    "@podium/podlet": "^4.2.0",
    "express": "^4.17.1"
  },
  "name": "userlogin",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "app":"node index"
  }
}
 
 

index.js

const express = require("express")
const Podlet = require("@podium/podlet")
const app = express();
const podlet = new Podlet({
    name: 'userlogin', // required
    version: '1.0.0', // required
    pathname: '/userlogin', // required
    manifest: '/manifest.json', // optional, defaults to '/manifest.json'
    development: true, // optional, defaults to false
});
app.use(podlet.middleware());
app.get(podlet.content(), (req, res) => {
    res.status(200).podiumSend(`
        <div>
            This is the userlogin podlet's HTML content
        </div>
    `);
});
app.get(podlet.manifest(), (req, res) => {
    res.status(200).send(podlet);
});
app.listen(7101);
 
 

Dockerfile

FROM node:alpine
LABEL AUTHOR="1141591465@qq.com"
WORKDIR /app
COPY . /app
RUN yarn
EXPOSE 7101
RUN yarn
CMD [ "yarn", "app"]
  • layouts/home
    package.json
 
{
  "name": "home",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "@podium/layout": "^4.2.0",
    "express": "^4.17.1"
  },
  "scripts": {
    "app":"node index"
  }
}
 
 

index.js

const express = require('express');
const Layout = require('@podium/layout');
const app = express();
const layout = new Layout({
    name: 'dashboard', // required
    pathname: '/', // required
});
const index = layout.client.register({
    name: 'index', // required
    uri: 'http://layout-index:7100/manifest.json', // required
});
const userlogin = layout.client.register({
    name: 'userlogin', // required
    uri: 'http://layout-userlogin:7101/manifest.json', // required
});
app.use(layout.middleware());
app.get('/', async (req, res,next) => {
    const incoming = res.locals.podium;
    const [a,b] = await Promise.all([
        index.fetch(incoming),
        userlogin.fetch(incoming),
    ]);
    incoming.view.title = 'My Super Page';
    res.podiumSend(`
    <section>${a.content}</section>
    <section>${b.content}</section>
`);
});
app.listen(7000);
 

Dockerfile

FROM node:alpine
LABEL AUTHOR="1141591465@qq.com"
WORKDIR /app
COPY . /app
RUN yarn
EXPOSE 7000
RUN yarn
CMD [ "yarn", "app"]

构建&&启动

  • 构建镜像
docker-compose  build
  • 启动
docker-compose up -d
  • 效果

打开 http://localhodt:7000

说明

podlets 提供片段服务,layout 提供webpage 的组合服务,使用上还是比较简单的,同时里边也包含了版本的处理(通过元数据服务)

参考资料

https://podium-lib.io/docs/podium/conceptual_overview
https://github.com/rongfengliang/podium-docker-compose

podium 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. jQuery无刷新上传之uploadify简单试用

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

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

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

  6. cloudevents js sdk 简单试用

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

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

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

  8. Cassandra安装及其简单试用

    官方主页:http://cassandra.apache.org/ 简介: The Apache Cassandra Project develops a highly scalable second ...

  9. nginx ngx_http_image_filter_module 简单试用

    nginx包含了一个ngx_http_image_filter_module 模块,我们可以方便的进行图片的缩略图,平时一些简单的功能 已经够用了 环境准备 为了简单使用docker-compose ...

随机推荐

  1. 『Blocks 区间dp』

    Blocks Description Some of you may have played a game called 'Blocks'. There are n blocks in a row, ...

  2. Git新建分支,分支合并,版本回退详解

    一.git基本命令 git拉取仓库代码 #拉取master代码 git clone git仓库地址 #拉取分支代码 git clone -b 分支名称 git仓库地址 2.git添加代码到本地仓库 g ...

  3. docker compose项目

    本文参考: https://www.cnblogs.com/jmcui/p/9395375.html https://www.cnblogs.com/jmcui/p/9512795.html 1.Do ...

  4. spring Boot 学习(八、Spring Boot与与监控管理)

    一.监控管理通过引入spring-boot-starter-actuator,可以使用Spring Boot为我们提供的准 生产环境下的应用监控和管理功能.我们可以通过HTTP,JMX,SSH协议来进 ...

  5. N(C)O(S)I(P)P 2019 退役记

    N(C)O(S)I(P)P 2019 退役记 day-4 今天下午老师突然咕了,于是一下午欢乐时光 今天上午考试T3线段树维护个区间加,区间乘 一遍过编译,一遍过样例(第一次,俺比较弱(虽然也发现和暴 ...

  6. JS基础 —— call、apply 和 bind

    函数的三个原型方法 作用:改变this指向 call MDN:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo ...

  7. Beego 学习笔记12:文件的操作

    文件的操作 1>     此事例操作的是text文件 2>     文件的操作有读取text内容,将内容写入到文件中,删除文件,创建文件 3>     新建一个控制器,名为rwfil ...

  8. android中app卡顿优化问题

     所谓app卡顿原因就是在运行时出现了丢帧,还可能是UI线程被阻塞.首先来一下丢帧现象,android每16ms会对界面进行一次渲染,如果app的绘制.计算等超过了16ms那么只能等下一个16ms才能 ...

  9. Java的常见术语(PO/POJO/VO/BO/DAO/DTO)

    PO(persistant object) 持久对象在o/r 映射的时候出现的概念,如果没有o/r映射,就没有这个概念存在了.通常对应数据模型(数据库),本身还有部分业务逻辑的处理.可以看成是与数据库 ...

  10. python工程化最佳实践

    1.pipenv 真实环境 vs virtualenv vs pipenv 2.自定义用户模型 继承BaseUserManager和AbstractBaseUser,在settings中指定AUTH_ ...