mirror of
https://github.com/crystelf/crystelf-core.git
synced 2025-10-14 05:19:19 +00:00
优化
This commit is contained in:
parent
8096228d96
commit
55de8a14bb
@ -9,7 +9,8 @@
|
||||
"dependencies": {
|
||||
"chalk": "4",
|
||||
"dotenv": "^16.0.0",
|
||||
"express": "^4.18.0"
|
||||
"express": "^4.18.0",
|
||||
"mkdirp": "^3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.0",
|
||||
|
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@ -17,6 +17,9 @@ importers:
|
||||
express:
|
||||
specifier: ^4.18.0
|
||||
version: 4.21.2
|
||||
mkdirp:
|
||||
specifier: ^3.0.1
|
||||
version: 3.0.1
|
||||
devDependencies:
|
||||
'@types/express':
|
||||
specifier: ^4.17.0
|
||||
|
43
src/app.ts
43
src/app.ts
@ -1,23 +1,48 @@
|
||||
import express from 'express';
|
||||
import logger from './utils/logger';
|
||||
import fc from './utils/file';
|
||||
import paths from './utils/path';
|
||||
import sampleController from './modules/sample/sample.controller';
|
||||
import imageController from './modules/image/image.controller';
|
||||
import config from './utils/config';
|
||||
import fc from './utils/file';
|
||||
|
||||
const apps = {
|
||||
createApp() {
|
||||
const app = express();
|
||||
|
||||
logger.info('晶灵核心初始化..');
|
||||
|
||||
app.use(express.json());
|
||||
app.use('/public', express.static(paths.get('public')));
|
||||
logger.debug(`路由/public挂载成功..`);
|
||||
app.use('/api/sample', sampleController.getRouter());
|
||||
logger.debug(`路由/api/sample挂载成功..`);
|
||||
app.use('/images', imageController.getRouter());
|
||||
logger.debug(`路由/images挂载成功..`);
|
||||
fc.createDir(paths.get('log'));
|
||||
logger.info('晶灵核心初始化成功!');
|
||||
logger.debug('成功加载express.json()中间件');
|
||||
|
||||
const publicPath = paths.get('public');
|
||||
app.use('/public', express.static(publicPath));
|
||||
logger.debug(`静态资源路由挂载:/public → ${publicPath}`);
|
||||
|
||||
const modules = [
|
||||
{ path: '/api/sample', name: '测试模块', controller: sampleController },
|
||||
{ path: '/images', name: '图像模块', controller: imageController },
|
||||
];
|
||||
|
||||
modules.forEach((module) => {
|
||||
app.use(module.path, module.controller.getRouter());
|
||||
logger.debug(`模块路由挂载: ${module.path.padEnd(12)} → ${module.name}`);
|
||||
|
||||
if (config.get('DEBUG', false)) {
|
||||
module.controller.getRouter().stack.forEach((layer) => {
|
||||
if (layer.route) {
|
||||
const methods = Object.keys(layer.route)
|
||||
.map((m) => m.toUpperCase())
|
||||
.join(',');
|
||||
logger.debug(` ↳ ${methods.padEnd(6)} ${module.path}${layer.route.path}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
const logPath = paths.get('log');
|
||||
fc.createDir(logPath);
|
||||
logger.debug(`日志目录初始化: ${logPath}`);
|
||||
logger.info('晶灵核心初始化完毕!');
|
||||
return app;
|
||||
},
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user