feat(server): 添加公共路径认证中间件和批量操作功能
refactor(routes): 重新组织路由顺序并添加批量删除功能 - 在server.js中添加公共路径认证中间件 - 为cables、devicePorts等路由添加批量删除功能 - 重新组织路由顺序,将相关操作分组 - 添加工单导出功能
This commit is contained in:
@@ -223,9 +223,32 @@ async function initializeApp() {
|
||||
|
||||
const swaggerUi = require('swagger-ui-express');
|
||||
const { specs, customCSS } = require('./swagger');
|
||||
const { authMiddleware } = require('./middleware/auth');
|
||||
|
||||
initializeApp();
|
||||
|
||||
const PUBLIC_PATHS = [
|
||||
'/auth',
|
||||
'/health',
|
||||
'/docs',
|
||||
'/api-docs',
|
||||
'/api-docs.json',
|
||||
];
|
||||
|
||||
const isPublicPath = (path) => {
|
||||
if (path === '' || path === '/') {
|
||||
return true;
|
||||
}
|
||||
return PUBLIC_PATHS.some((publicPath) => path === publicPath || path.startsWith(publicPath + '/'));
|
||||
};
|
||||
|
||||
app.use('/api', (req, res, next) => {
|
||||
if (isPublicPath(req.path)) {
|
||||
return next();
|
||||
}
|
||||
return authMiddleware(req, res, next);
|
||||
});
|
||||
|
||||
const deviceRoutes = require('./routes/devices');
|
||||
const rackRoutes = require('./routes/racks');
|
||||
const roomRoutes = require('./routes/rooms');
|
||||
|
||||
Reference in New Issue
Block a user