fix: 修复consumableImport.js路由级authMiddleware拦截所有/api请求的问题

consumableImport.js挂载在/api根路径,使用router.use(authMiddleware)
会拦截所有/api/*请求(包括公开路由如/api/auth/login),
导致登录等公开接口返回401。

修复方案:移除router.use(authMiddleware),改为在每个具体路由上
单独添加authMiddleware中间件。
This commit is contained in:
zhang96110
2026-04-02 03:35:23 +00:00
parent dc20bdba1f
commit 1bda91b93e
6 changed files with 46 additions and 47 deletions
+4
View File
@@ -2,6 +2,10 @@ const express = require('express');
const path = require('path');
const fs = require('fs');
const router = express.Router();
const { authMiddleware } = require('../middleware/auth');
// 所有背景设置路由需要认证
router.use(authMiddleware);
const UPLOAD_DIR = path.join(__dirname, '../uploads');
if (!fs.existsSync(UPLOAD_DIR)) {