import express from 'express'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const app = express(); // 默认端口 8080,但优先遵循 Cloud Run 的 PORT 环境变量 const PORT = process.env.PORT || 8080; // 托管构建后的静态文件目录 const distPath = path.join(__dirname, 'dist'); app.use(express.static(distPath)); // 处理 SPA 路由,将所有请求重定向到 index.html app.get('*', (req, res) => { res.sendFile(path.join(distPath, 'index.html')); }); app.listen(PORT, '0.0.0.0', () => { console.log(`SocioPal is running on port ${PORT}`); console.log(`Serving static files from: ${distPath}`); });