0.1.10 • Published 5 years ago
ync-koa2-static-server v0.1.10
简介
基于 koa2 搭建的静态服务。可以运行 React BrowserRouter 构建的前端页面。
如何开发
# 安装依赖
npm ci
# 发布
npm publish --access=public如何使用
安装
# 安装
npm i ync-react-modal --save默认开启健康检查和spa单页
const koa = require('ync-koa2-static-server');
const app = new koa();
const port = process.env.PORT || 6001;
app.start(port);自定义健康检查
const koa = require('ync-koa2-static-server');
const app = new koa({ health: {
{
path: '/healthCheck',
body: 'success'
}
}});
const port = process.env.PORT || 6001;
app.start(port);自定义 SPA 单页渲染
const koa = require('ync-koa2-static-server');
const app = new koa({ spa: {
entry: 'dist',
spa: {
index:'entry',
ext: '.htm'
},
}});
const port = process.env.PORT || 6001;
app.start(port);默认参数
{
spa={
entry: 'build',
spa: {
name: 'index',
ext: '.html'
}
},
health={
path: '/health',
body: 'ok'
}
}参数描述
| 参数名 | 类型 | 是否必须 | 说明 | 默认值 |
|---|---|---|---|---|
| spa.entry | string | 否 | react 构建目录名称 | build |
| spa.spa.name | string | 否 | react 构建目录启动文件名(不含文件扩展名) | index |
| spa.spa.ext | string | 否 | react 构建目录启动文件扩展名 | .html |
| health.path | string | 否 | koa2 静态服务健康检查地址 | /health |
| health.body | string | 否 | koa2 静态服务健康检查响应 | ok |