fix 502
This commit is contained in:
25
frontend/server.cjs
Normal file
25
frontend/server.cjs
Normal file
@@ -0,0 +1,25 @@
|
||||
const express = require('express');
|
||||
const { createProxyMiddleware } = require('http-proxy-middleware');
|
||||
const path = require('path');
|
||||
|
||||
const app = express();
|
||||
|
||||
// API 代理
|
||||
app.use('/api', createProxyMiddleware({
|
||||
target: 'http://backend:3001',
|
||||
changeOrigin: true,
|
||||
}));
|
||||
|
||||
// 静态文件服务
|
||||
const staticPath = path.join(__dirname, 'dist');
|
||||
app.use(express.static(staticPath));
|
||||
|
||||
// 处理所有其他路由,返回 index.html
|
||||
app.get('*', (req, res) => {
|
||||
res.sendFile(path.join(staticPath, 'index.html'));
|
||||
});
|
||||
|
||||
const port = process.env.PORT || 3000;
|
||||
app.listen(port, '0.0.0.0', () => {
|
||||
console.log(`Server is running on port ${port}`);
|
||||
});
|
||||
Reference in New Issue
Block a user