2021-12-06 23:26:38 +08:00
|
|
|
import koa from "koa";
|
|
|
|
import Router from "koa-router";
|
|
|
|
import koaBody from "koa-body";
|
|
|
|
import * as path from "path";
|
|
|
|
import RouterMW from "./middleware/controllerEngine";
|
|
|
|
|
|
|
|
import config from "./config";
|
|
|
|
import handleError from "./middleware/handleError";
|
|
|
|
import init from "./middleware/init";
|
|
|
|
import SqliteUtil from './util/SqliteHelper';
|
|
|
|
import log from './util/LogUtil';
|
2023-07-28 20:12:34 +08:00
|
|
|
import QbService from './service/QbService';
|
|
|
|
import qbService from "./service/QbService";
|
2021-12-06 23:26:38 +08:00
|
|
|
|
|
|
|
console.log(config);
|
2023-03-07 00:06:59 +08:00
|
|
|
|
2021-12-06 23:26:38 +08:00
|
|
|
const app = new koa();
|
|
|
|
|
|
|
|
let router = new Router({
|
2023-03-07 00:06:59 +08:00
|
|
|
prefix: config.urlPrefix
|
2021-12-06 23:26:38 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
app.use(require('koa-static')(path.join(config.rootPath, 'static')));
|
|
|
|
|
|
|
|
//表单解析
|
|
|
|
app.use(koaBody(config.bodyLimit));
|
|
|
|
//请求预处理
|
|
|
|
app.use(init);
|
|
|
|
//错误处理
|
|
|
|
app.use(handleError);
|
|
|
|
|
|
|
|
app.use(RouterMW(router, path.join(config.rootPath, "dist/api")));
|
|
|
|
(async () => {
|
2023-03-07 00:06:59 +08:00
|
|
|
await SqliteUtil.createPool();
|
2023-07-28 20:12:34 +08:00
|
|
|
await qbService.init();
|
2023-03-07 00:06:59 +08:00
|
|
|
app.listen(config.port);
|
|
|
|
log.info(`server listened `, config.port);
|
2021-12-06 23:26:38 +08:00
|
|
|
})();
|
|
|
|
|
|
|
|
app.on("error", (error) => {
|
2023-03-07 00:06:59 +08:00
|
|
|
console.error(error);
|
2021-12-06 23:26:38 +08:00
|
|
|
})
|