This commit is contained in:
2025-07-08 18:46:12 +08:00
parent 162c0555ec
commit caa855717f
3 changed files with 30 additions and 3 deletions

View File

@@ -34,4 +34,4 @@ EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:3000 || exit 1
# 启动命令
CMD ["npm", "run", "start"]
CMD ["node", "server.cjs"]

View File

@@ -4,7 +4,7 @@
"description": "Pandora 前端应用",
"type": "module",
"scripts": {
"start": "vite preview --host 0.0.0.0 --port 3000",
"start": "node server.cjs",
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
@@ -26,7 +26,9 @@
"vee-validate": "^4.10.5",
"vue": "^3.3.4",
"vue-router": "^4.2.4",
"vue-toastification": "^2.0.0-rc.5"
"vue-toastification": "^2.0.0-rc.5",
"express": "^4.18.2",
"http-proxy-middleware": "^2.0.6"
},
"devDependencies": {
"@types/node": "^20.6.3",

25
frontend/server.cjs Normal file
View 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}`);
});