xtd
v1.0.0
Published
一个简单的koa@2的后台项目模板
Downloads
3
Readme
xtd
一个简单的koa@2的后台项目模板
使用
var XTD = require('xtd');
let app = new XTD({
port: 5657
});
app.use(async(ctx, next) => {
let date = new Date();
await next();
let d = new Date - date;
ctx.set('x-res-time', d)
})
//开启压缩
app.useCompress();
//启用Session
app.useSession();
//使用路由在router目录下
// 有一个 demo.js
// 'GET /index': async(ctx) => {
// ctx.body = ctx.path;
// },
// 其中GET为请求方法
// /index 为路径
// 后面的为路由方法
// 地址栏的URL为: get /demo/index
// 如果demo.js在router目录下的api目录中
// 那么地址栏URL为: get /api/demo/index
//
app.useRouter(__dirname + '/router');
app.useStatic(__dirname);
//默认开启文件上传
app.useBodyParse();
app.use(async(ctx, next) => {
ctx.body = 'hello td';
await next();
});
app.start();