From c8842710dd82a25fce19e25d4a2a2b863596a282 Mon Sep 17 00:00:00 2001 From: huanglinhuan Date: Thu, 15 Jan 2026 15:40:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0server.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server.js b/server.js index cce2bc8..afd3e44 100755 --- a/server.js +++ b/server.js @@ -8,6 +8,7 @@ const { authenticateToken } = require('./middleware/auth'); const app = express(); const PORT = process.env.PORT || 3001; +const FRONTEND_DIR = path.join(__dirname, '..', 'department-web', 'build'); // 中间件 app.use(cors()); @@ -16,6 +17,7 @@ app.use(express.urlencoded({ extended: true })); // 静态文件服务 - 用于提供PDF文件 app.use('/uploads', express.static(path.join(__dirname, 'uploads'))); +app.use(express.static(FRONTEND_DIR)); // 路由 app.use('/api/auth', authRoutes); @@ -27,6 +29,11 @@ app.get('/api/health', (req, res) => { 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, () => { console.log(`服务器运行在端口 ${PORT}`); });