0.1.27 • Published 3 years ago
framework-services-es6 v0.1.27
使用说明
安装
npm install framework-services-es6
使用
const service = require("framework-services-es6")
service(option)
配置参数option
option={
//当前服务端口
serverPort: 3200,
//日志存放目录
logPath: "logs",
//数据库连接设置
db_settings: {
mssql: {
server: "127.0.0.1",
user: "sa",
pwd: "123456",
database: "test"
},
redis: {
server: "127.0.0.1",
port: 6379,
pwd: "123456",
database: "test"
},
mongo: {
server: "127.0.0.1",
port: 27000,
user: "root",
pwd: "123456",
database: "test"
},
mysql: {
server: "127.0.0.1",
port: 3306,
user: "root",
pwd: "123456",
database: "test"
}
},
//当前需要使用的数据库连接,可选项有:redis,mssql,mongo,sub
//其中,sub 为redis的订阅服务,与redis连接共用一个redis连接配置
dbs: ["redis", "sub"],
//当前使用的中间件,会按顺序注入,务必注意调用循序
/*可选项有
logger:日志组件
bodyParse,body格式化组件,但如果post文件的话不会进行格式化
cache:{缓存组件(未完成)
rules:{不走缓存的path列表
path:{
enabled:是否缓存
timeout:缓存时间秒
}
timeout:默认缓存时间,(所有不在rules中出现的path,都会缓存结果)
}
}
debounce(debounce_mut):二选一,防抖组件,相同请求会等待上一次的结果来返回
proxy:{ 负载代理
proxySource:{代理服务器配置
请求的host:{
targer:目标服务器
paths:白名单
[
{
path:"路径",
repath:"替换路径" ,即,{path:"/a",repath:"/b"} 访问/a/xxx会变成 /b/xxx
}
]
unpaths:黑名单(优先)
weight:权重,
healtCheck: 健康检查接口
}
}
}
router:{自定义接口处理
routerPath:"router所存放的目录"
}
response:响应结果,走代理的话不会走到这里,
timmer:{定时器构造,顺序随意,尽量放在最后
timerPath:定时器放置位置
}
*/
middlewares:["logger","bodyParse","xmlparser",
{
name:"cache",
unpaths:[""]//不代理
},
"debounce",
{
name:"proxy",
proxySource:{
"127.0.0.1": [{
targer: "http://localhost:80",
paths: [{
name:"/pft",
repath:"/open"
}],//白名单
unpaths: [],//黑名单
weight: 10,
healtCheck: "test/index"
}],
"localhost": [{
targer: "http://localhost:30001",
paths: [],
unpaths: [],
weight: 10
}, {
targer: "http://localhost:30002",
paths: [],
unpaths: [],
weight: 30
}]
}
},{
name: "router",
basePath:"api",
routerPath: path.join(__dirname, "routers")
}
"router","response",
{
name:"timmer",
timerPath: path.join(__dirname, "timers")
}
]
// middlewares: ["logger", "bodyParse", "response"]
}
最近一次成功的配置文件范例
const path = require("path")
const service = require("framework-services-es6")
service.services({
serverPort: 3200,
logPath: "logs",
middlewares: ["logger", {
name: "bodyParse"
}, "xmlparser", {
name: "cache",
rules: []
}, "debounce", {
name: "router",
basePath: "api",
routerPath: path.join(__dirname, "src", "routers")
}, "response"],
db_settings: {
mongo: {
server: "**********",
port: 27017,
user: "root",
pwd: "123",
database: "test-egg"
}
},
dbs: ["mongo"],
})
版本变化
0.0.*
初始化项目,测试阶段
0.1.0
初步可用阶段
0.1.4
1.代理模式下,增加服务器存活判断
0.1.5
1.代理模式下,修正服务器存活判断的bug 2.防抖模式的way更换文字为“wait”
0.1.6
1.防抖事件监听最大数量设置为1000
0.1.7
1.修复定时器无效的bug
0.1.9
1.增加自定义中间件处理
middlewares[(app)=>{
app.use((req,res,next)=>{
//do something
})
}]
```
## 0.1.12
1.增加日志判断,如果没有设置“logpath”的话,将会直接console.log打印
## 0.1.13
1.增加express-xml-bodyparser处理微信等xml数据
## 0.1.14
1.路由配置增加初始path
## 0.1.15
1.修正0.1.14的bug
## 0.1.16
1.http_handler 返回req与res,方便使用
## 0.1.17
1.修正url传参的bug
## 0.1.18
1.增加文件上传处理,在req.files中有文件实体
## 0.1.19
1.增加swagger处理(必须在router处理的前面)
## 0.1.20
1.增加httphandler前的处理
## 0.1.21
1.修正mongodb报错未处理的问题
## 0.1.22
1.调整响应结构,router只需返回正确结果,错误信息通过抛出异常来处理
## 0.1.23
1.调整0.1.22引起的防抖和缓存的问题
## 0.1.24
1.重新梳理逻辑,使得框架用户可以随时随地调用数据库方法
## 0.1.25
1.修正bug
## 0.1.26
1.修正bug
0.1.27
3 years ago
0.1.23
3 years ago
0.1.24
3 years ago
0.1.25
3 years ago
0.1.26
3 years ago
0.1.22
3 years ago
0.1.20
3 years ago
0.1.21
3 years ago
0.1.19
3 years ago
0.1.18
3 years ago
0.1.17
3 years ago
0.1.16
3 years ago
0.1.15
3 years ago
0.1.14
3 years ago
0.1.13
3 years ago
0.1.12
3 years ago
0.1.11
3 years ago
0.1.10
3 years ago
0.1.9
3 years ago
0.1.8
3 years ago
0.1.7
3 years ago
0.1.6
3 years ago
0.1.4
3 years ago
0.1.5
3 years ago
0.1.3
3 years ago
0.0.10
3 years ago
0.1.0
3 years ago
0.1.2
3 years ago
0.1.1
3 years ago
0.0.9
3 years ago
0.0.8
3 years ago
0.0.7
3 years ago
0.0.6
3 years ago
0.0.5
3 years ago
0.0.3
3 years ago
0.0.2
3 years ago
0.0.4
3 years ago
0.0.1
3 years ago