Files
ClassContent/历届学生/陈尧瑞/OfficialWebsite/src/www/init.ts
2024-09-27 02:06:13 +08:00

36 lines
741 B
TypeScript
Executable File

import koa from "koa";
import stati from "koa-static";
import path from "path";
import views from "koa-views";
/**
* 配置所有koa2的中间件
*/
export class init {
protected koa2:any = new koa();
private PluginsArray: Function[];
constructor () {
this.initPlugins();
}
private initPlugins(): any {
this.PluginsArray = [
views(path.join( __dirname, "../resource/view"),{
map: {
jade: 'jade'
},
extension: 'jade'
}),
stati(path.join( __dirname, "../resource/static") ,{
maxage: 3000
})
];
try {
this.PluginsArray.forEach( v => this.koa2.use(v));
} catch (e) {
throw new Error(`配置插件出错:${e.message}`)
}
}
}