podium layout 说明
layout 主要是进行podlets 的组合,同时也提供了context ,fallback,以及传递参数的处理
基本代码
const express = require('express');
const Layout = require('@podium/layout');
const app = express();
const layout = new Layout({
name: 'myLayout',
pathname: '/demo',
});
const podlet = layout.client.register({
name: 'myPodlet',
uri: 'http://localhost:7100/manifest.json',
});
app.use(layout.middleware());
app.get('/demo', async (req, res) => {
const incoming = res.locals.podium;
const response = await podlet.fetch(incoming);
incoming.view.title = 'My Super Page';
res.podiumSend(`<div>${response}</div>`);
});
app.listen(7000);
context
- 自定义context
比如进行header 的处理,对于不同规则传递不同后端
const CustomContext = require('my-custom-context-parser');
...
// Register custom context with layout
layout.context.register('my-custom-context', new CustomContext());
处理podlet 不可用
- 超时定义
const layout = new Layout({
...
client: {
timeout: 2000,
}
});
- 异常处理
const gettingStarted = layout.client.register({
...
throwable: true,
})
依赖拦截处理
app.get('/', (req, res, next) => {
try {
const content = await gettingStarted.fetch(res.locals.podium);
...
} catch(err) {
// you might handle this directly...
// res.status(500).send('The getting started guide is currently unavailable');
// or perhaps just pass the error on to be handled in error handling middleware
// next(err);
}
});
查询参数传递
- 传递查询参数
const content = await Promise.all([
searchField.fetch(incoming, { query: { search: req.query.search } }),
searchResults.fetch(incoming, { query: { search: req.query.search } }),
]);
- 传递pathname
layout 端:
const content = podlet.fetch(incoming, { pathname: '/andrew' });
podlet 端:
app.get('/:name', (req, res) => {
// req.params.name => andrew
});
说明如果content 路由不是/ 而是/content 的需要参考如下修改:
const podlet = new Podlet({
content: '/content',
});
app.get('/content/:name', (req, res) => {
// req.params.name => andrew
});
资源处理
资源主要是css 以及js 文件,以下为几种处理方式
- podlet 基于暴露的api 提供css 以及js 的
podlet.js({ value: `http://my-podlet.com/assets/scripts.js` });
podlet.css({ value: `http://my-podlet.com/assets/styles.js` });
- 通过express 提供资源处理
实际上这种不对于资源的处理需要的layout 端的
app.use('/assets', express.static('assets'));
- podiumSend 以及文档模版自己编写资源处理
app.get('/', (req, res) => {
res.podiumSend(`<div>Content goes here</div>`);
});
- 通过cdn 提供资源服务
这种适合有资源的情况,一般是偏大的项目
关于本地开发模式的配置
- 使用forever提升开发体验
运行方式:
forever start /path/to/development.json
json 配置文件(主要是关于podlet 以及layout 服务)
参考格式:
[
{
"uid": "header",
"append": true,
"watch": true,
"script": "index.js",
"sourceDir": "/path/to/podlets/header"
},
{
"uid": "navigation",
"append": true,
"watch": true,
"script": "index.js",
"sourceDir": "/path/to/podlets/navigation"
},
{
"uid": "home",
"append": true,
"watch": true,
"script": "index.js",
"sourceDir": "/path/to/podlets/home"
},
{
"uid": "footer",
"append": true,
"watch": true,
"script": "index.js",
"sourceDir": "/path/to/podlets/footer"
},
{
"uid": "homePage",
"append": true,
"watch": true,
"script": "index.js",
"sourceDir": "/path/to/layouts/home"
}
]
- 使用pm2
类似的工具,pm2 做为实际项目的运行工具是一个很不错的选择
参考资料
https://podium-lib.io/docs/layout/getting_started
https://podium-lib.io/docs/api/document
https://github.com/rongfengliang/podium-docker-compose
podium layout 说明的更多相关文章
- podium micro-frontends 简单试用
以下是一个简单的podium 试用,包含了layout 以及podlets,使用docker 运行 podium 主要包含了两大部分 podlets 片段服务 layouts 片段组合服务 环境准备 ...
- podium服务器端的微前端开发框架
podium 是一个比较全的微前端开发框架. 具有以下特性 自治开发 强大的组合能力 基于约定的开发模式 podium 包含的组件 podlets 页面片段,是一个独立的http 服务,独立运行的,实 ...
- podium podlets 说明
podlets 提供了一个页面片段服务,podlets 包含了一些元数据信息,通过json 暴露, 主要包含以下内容 一个 http endpoint 提供主要内容 一个 http endpoint ...
- 前端框架 EasyUI (2)页面布局 Layout
在 Web 程序中,页面布局对应用程序的用户体验至关重要. 在一般的信息管理类的 Web 应用程序中,页面结构通常有一个主工作区,然后在工作区上下左右靠近边界的区域设置一些边栏,用于显示信息或放置一些 ...
- Android Studio分类整理res/Layout中的布局文件(创建子目录)
res/layout中的布局文件太杂,没有层次感,受不了的我治好想办法解决这个问题. 前几天看博客说可以使用插件分组,可惜我没找到.知道看到另一篇博客时,才知道这个方法不能用了. 不能用插件,那就手动 ...
- 如何在ASP.NET Web站点中统一页面布局[Creating a Consistent Layout in ASP.NET Web Pages(Razor) Sites]
如何在ASP.NET Web站点中统一页面布局[Creating a Consistent Layout in ASP.NET Web Pages(Razor) Sites] 一.布局页面介绍[Abo ...
- [Android]异步 layout inflation(翻译)
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/5829809.html 异步 layout inflation ...
- Express 4 handlebars 不使用layout写法
Express 4 handlebars 不使用layout写法 Express node nodejs handlebars layout 最近刚开始学习使用nodejs. 使用express搭建了 ...
- Android在layout xml中使用include
Android include与merge标签使用详解 - shuqiaoniu的博客 - 博客频道 - CSDN.NEThttp://blog.csdn.net/shuqiaoniu/article ...
随机推荐
- vue nexttick的理解和使用场景
应用场景 需要在视图更新之后,基于新的视图进行操作 文档说明 在下次 DOM 更新循环结束之后执行延迟回调.在修改数据之后立即使用这个方法,获取更新后的 DOM nextTick原理 1.异步说明 V ...
- .net core 2.0的认证和授权
在asp.net core中,微软提供了基于认证(Authentication)和授权(Authorization)的方式,来实现权限管理的,本篇博文,介绍基于固定角色的权限管理和自定义角色权限管理, ...
- Java学习:Lambda表达式
Lambda表达式 函数式编程思想概述---强调做什么,而不是以什么形式做 面向对象的思想: 做一件事情,找一个能解决这个的事情的对象,调用对象的方法,完成事情 函数式编程思想 只要能获取到结果,谁去 ...
- latex制作表格-跨行跨列
1.列的合并,使用 \multicolumn{跨几列}{格式}{填充内容} \documentclass[UTF8]{ctexart} \begin{document} 三囚犯问题进行300次实验后\ ...
- VS 发布MVC网站缺少视图
mvc项目发布之后会有一些视图文件缺少,不包含在发布文件中,虽然可以直接从项目文件中直接拷贝过来,但还是想知道是什么原因,发布文件好像没有找到哪里有设置这个的地方 把生成操作:无-改成内容即可 原文
- 端口排查步骤-7680端口分析-Dosvc服务
出现大量7680端口的内网连接,百度未找到端口信息,需证明为系统服务,否则为蠕虫 1. 确认端口对应进程PID netstat -ano 7680端口对应pid:6128 2. 查找pid对应进程 t ...
- ansible模块command、shell、raw、script
简介 环境: ansible端: ip:192.168.100.129 hostname:node1.lansgg.com client端: ip:192.168.100.131 hostname:v ...
- C#汉字转为Unicode编码
主要用于生成json格式时,将汉字转成Unicoude编码,防止页面乱码. protected string GetUnicode(string text) { string result = &qu ...
- JS项目练习之求和(包含正则表达式验证)
最近在准备专升本,抽一点时间敷衍一下大家!!!嘿嘿嘿!!! 话不多说,上代码: <!DOCTYPE html> <html lang="zh-CN"> &l ...
- select用法 多并发处理
select默认最大检查套接口数量是1024,有定义 #define __NFDBITS (8 * sizeof(unsigned long)) #define __FD_SETSIZE 1024 # ...