feat(server): 添加认证授权和日志记录功能
- 实现了 JWT 认证中间件,支持 token 验证和白名单路由 - 添加了登录接口,支持用户登录和 token 生成 - 集成了 log4js 日志系统,支持 mysql 和 koa 日志分类 - 配置了环境变量支持,添加了 SECRET_KEY 配置 - 重构了 MySQL 连接池配置,添加了查询日志记录 - 集成了 koa 路由和认证中间件,实现接口访问控制
This commit is contained in:
@@ -2,28 +2,30 @@ import Koa from 'koa';
|
||||
import Router from 'koa-router';
|
||||
import config from "../config/index.js"
|
||||
import koaStatic from 'koa-static';
|
||||
import registry from "./registry.js";
|
||||
import * as log4js from "../log4js.js";
|
||||
import auth from "./auth.js";
|
||||
|
||||
const app = new Koa();
|
||||
const router = new Router();
|
||||
|
||||
|
||||
// 简单的路由示例
|
||||
router.get('/', (ctx) => {
|
||||
ctx.body = {message: 'Hello from Koa server!'};
|
||||
});
|
||||
|
||||
router.get('/api/test', (ctx) => {
|
||||
ctx.body = {message: 'This is a test API endpoint'};
|
||||
});
|
||||
|
||||
router.get('/api/config', (ctx) => {
|
||||
ctx.body = {data: config}
|
||||
})
|
||||
app.use(auth)
|
||||
app.use(router.routes());
|
||||
app.use(registry)
|
||||
app.use(router.allowedMethods());
|
||||
app.use(koaStatic('/www'))
|
||||
|
||||
const PORT = process.env.PORT || 3001;
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Koa server is running on port ${PORT}`);
|
||||
log4js.koa.info(`Koa server is running on port ${PORT}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user