Files
ai-app-skg/server.js
2025-12-24 00:52:40 +08:00

27 lines
747 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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}`);
});