更新server.js
This commit is contained in:
@@ -8,6 +8,7 @@ const { authenticateToken } = require('./middleware/auth');
|
|||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = process.env.PORT || 3001;
|
const PORT = process.env.PORT || 3001;
|
||||||
|
const FRONTEND_DIR = path.join(__dirname, '..', 'department-web', 'build');
|
||||||
|
|
||||||
// 中间件
|
// 中间件
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
@@ -16,6 +17,7 @@ app.use(express.urlencoded({ extended: true }));
|
|||||||
|
|
||||||
// 静态文件服务 - 用于提供PDF文件
|
// 静态文件服务 - 用于提供PDF文件
|
||||||
app.use('/uploads', express.static(path.join(__dirname, 'uploads')));
|
app.use('/uploads', express.static(path.join(__dirname, 'uploads')));
|
||||||
|
app.use(express.static(FRONTEND_DIR));
|
||||||
|
|
||||||
// 路由
|
// 路由
|
||||||
app.use('/api/auth', authRoutes);
|
app.use('/api/auth', authRoutes);
|
||||||
@@ -27,6 +29,11 @@ app.get('/api/health', (req, res) => {
|
|||||||
res.json({ status: 'ok', message: 'API服务运行正常' });
|
res.json({ status: 'ok', message: 'API服务运行正常' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('*', (req, res, next) => {
|
||||||
|
if (req.path.startsWith('/api')) return next();
|
||||||
|
res.sendFile(path.join(FRONTEND_DIR, 'index.html'));
|
||||||
|
});
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
console.log(`服务器运行在端口 ${PORT}`);
|
console.log(`服务器运行在端口 ${PORT}`);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user