Files
ai/frontend/server.cjs
2025-07-08 18:46:12 +08:00

25 lines
649 B
JavaScript

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}`);
});