first commit

This commit is contained in:
编码猿
2024-09-27 02:06:13 +08:00
commit 852d94fbb9
36760 changed files with 3274413 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
/**
* 启动文件
*/
import "reflect-metadata";
import { init } from "./init";
import { createConnection } from "typeorm";
import { useKoaServer,useContainer } from "routing-controllers"
import { Container } from "typedi";
import { config } from "../config";
import path from "path"
export class App extends init {
private Apps: any;
constructor() {
super();
// 注册依赖注入
useContainer(Container);
// @ts-ignore
createConnection(config.typeOrm).then(connection => {
this.Apps = useKoaServer(this.koa2,{
cors: true,
validation: true,
controllers: [ path.join(__dirname,'../controller/*.{js,ts}') ]
});
this.start();
}).catch(error => {
console.log(`数据库连接出错:${error}`)
});
}
private start(): any {
this.Apps.listen(3000,function () {
console.log(`程序运行在: http://127.0.0.1:${3000}`)
})
}
}

View File

@@ -0,0 +1,36 @@
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}`)
}
}
}