shaogen1995 1 주 전
부모
커밋
fda2ea7294
4개의 변경된 파일21개의 추가작업 그리고 27개의 파일을 삭제
  1. 12 11
      src/app.ts
  2. 7 7
      src/config/config.default.ts
  3. 1 8
      src/middleware/index.ts
  4. 1 1
      src/middleware/validator/issueValidator.ts

+ 12 - 11
src/app.ts

@@ -26,17 +26,18 @@ app.use(proofZhong);
 
 // 日志中间件
 if (isEnv) app.use(morgan('dev'));
-else {
-  // 创建一个写入流(追加模式)
-  const accessLogStream = fs.createWriteStream(
-    path.join(import.meta.dirname, 'config/access.log'),
-    {
-      flags: 'a',
-    }
-  );
-
-  app.use(morgan('combined', { stream: accessLogStream }));
-}
+// 这个日志没有必要记录,nigix会记录更详细的
+// else {
+//   // 创建一个写入流(追加模式)
+//   const accessLogStream = fs.createWriteStream(
+//     path.join(import.meta.dirname, 'config/access.log'),
+//     {
+//       flags: 'a',
+//     }
+//   );
+
+//   app.use(morgan('combined', { stream: accessLogStream }));
+// }
 
 // 导入路由
 app.use('/api/v1', router);

+ 7 - 7
src/config/config.default.ts

@@ -1,16 +1,10 @@
 // 400 - 参数错误
 // 401 - 没有接口权限/没有传token/token失效
 // 402 - proof错误
-// 500 - 服务器代码错误
+// 500 - 服务器内部错误
 // 404 - 没有找到数据
 // 0   - 接口正常
 
-// 端口号
-export const MY_ROOT = 8500;
-
-// 生成token的秘钥
-export const tokenKey = 'f9cb1541-b570-495b-b40e-d80c11275277';
-
 // 本地环境和生产环境
 export const isEnv = process.env.NODE_ENV === 'development';
 
@@ -31,5 +25,11 @@ export const upStaticFileUrl = '/data/data/museum_anhui_hefei_guojia_tongbufushe
 // 写入日志路径
 export const writeLogUrl = '/data/data/node_porject/museum_anhui_hefei_guojia_tongbufusheshiyanshi';
 
+// 服务器端口号
+export const MY_ROOT = 8500;
+
+// 生成token的秘钥
+export const tokenKey = 'f9cb1541-b570-495b-b40e-d80c11275277';
+
 // 服务器链接地址
 export const mongodbUrl = isEnv ? envUrl : buildUrl;

+ 1 - 8
src/middleware/index.ts

@@ -11,13 +11,6 @@ export const isAdminZhong = (req: any, res: any, next: any) => {
 };
 
 // 2:----------------捕捉路由中的错误
-
-// 这个好像没啥用
-// export const asyncHandler = (fn: any) => (req: any, res: any, next: any) => {
-//   // 确保 fn 返回的 Promise 被捕获,任何异常都会通过 catch 传递给 next
-//   Promise.resolve(fn(req, res, next)).catch(next);
-// };
-
 export const errorHandler = (err: any, req: any, res: any, next: any) => {
   // 记录错误日志,便于后端排查
   // console.error('错误处理中间件捕获到异常:', err);
@@ -31,7 +24,7 @@ export const errorHandler = (err: any, req: any, res: any, next: any) => {
       method: req.method,
       url: req.originalUrl,
       userName,
-      apiDescription: req.apiDescription || '',
+      apiDescription: req.apiDescription || '-',
       ip: ipLocResFu(req), // 获取IP
       userAgent: req.get('User-Agent'), // 获取User-Agent
     };

+ 1 - 1
src/middleware/validator/issueValidator.ts

@@ -34,5 +34,5 @@ export const addShareVali = errorBack([
   body('name').notEmpty().withMessage('标题不能为空'),
   body('releaseDate').notEmpty().withMessage('发布日期不能为空'),
   body('type').notEmpty().withMessage('类别不能为空'),
-  body('cover').notEmpty().withMessage('封面地址不能为空'),
+  // body('cover').notEmpty().withMessage('封面地址不能为空'),
 ]);