Dee - 框架
优点
- 设计驱动开发,逻辑尽可能采用描述性文档表达。
- 使用 swagger 注册路由,解析并校验请求,提高开发效率。
- 更具描述实例化服务。
- 路由函数同时支持 callback/promsie。
入门
index.js
Dee({
config: {
name: 'MyApp',
host: 'localhost',
port: 3000,
prod: false
},
swaggerize: {
swaggerFile: path.resolve(__dirname, './swagger.yaml'),
handlers: require('./handlers'),
security: require('./security'),
routeIteratee: function(route) {
return route;
}
},
beforeRoute: funtion(app) {
app.use(funtion(req, res, next) {
next();
});
},
afterRoute: [
funtion(req, res, next) {
next();
}
],
errorHandler: funtion(err, req, res, next) {
},
ready: funtion(dee) {
},
services: {
redis: {
constructor: 'redis',
},
mongoose: {
constructor: 'mongoose',
construtorArgs: {
uri: 'mongodb://localhost/test'
}
},
sequelize: {
constructor: 'sequelize',
construtorArgs: {
database: 'test',
username: 'root',
password: 'mysql',
options: {
dialect: 'mysql',
operatorsAliases: false
}
}
},
}
}, funtion (err, dee) {
if (err) throw err;
dee.start();
});
swagger.yaml
swagger: "2.0"
info:
version: "0.0.1"
title: Hello World App
host: localhost:3000
basePath: /
schemes:
- http
- https
consumes:
- application/json
produces:
- application/json
paths:
/hello:
get:
description: Returns 'Hello' to the caller
operationId: hello
parameters:
- name: name
in: query
description: The name of the person to whom to say hello
required: false
type: string
responses:
"200":
description: Success
schema:
$ref: "#/definitions/HelloWorldResponse"
definitions:
HelloWorldResponse:
required:
- message
properties:
message:
type: string
controllers.js
funtion hello(req, res, next) {
req.swagger.params
req.srvs
res.end('')
}
async funtion hello(req, res, next) {
return new Promise(funtion(resolve, reject) {
req.swagger.params
req.srvs
res.end('')
resolve(next());
});
}
cli
node index.js
services
- redis
- mongoos
- sequelize
- logger
test
测试核心
npm test
测试服务
npm run test:srvs