app.ts 913 B

123456789101112131415161718192021222324252627282930
  1. import express, { type Express } from 'express';
  2. import cors from 'cors';
  3. import qiweiRoutes from './routes/qiwei.routes.js';
  4. import healthRoutes from './routes/health.routes.js';
  5. import aggregateRoutes from './routes/aggregate.routes.js';
  6. import usersRoutes from './routes/users.routes.js';
  7. import { errorHandler } from './http/error-handler.js';
  8. import { notFoundHandler } from './http/not-found.middleware.js';
  9. const app: Express = express();
  10. app.use(cors());
  11. app.use(express.json());
  12. // 企微 API 操作(Webhook / 同步 / 群操作 / 发消息 / 账号测试)
  13. app.use('/api/qiwe', qiweiRoutes);
  14. // 聚合计数(替代前端 N+1 count 查询)
  15. app.use('/api/aggregate', aggregateRoutes);
  16. // 用户管理(_User 表操作,需 masterKey)
  17. app.use('/api/users', usersRoutes);
  18. // 健康检查
  19. app.use('/api', healthRoutes);
  20. app.use(notFoundHandler);
  21. app.use(errorHandler);
  22. export default app;