This commit is contained in:
Daniel
2026-03-04 00:39:01 +08:00
parent 95e2fe1c41
commit 3264b3252a
8 changed files with 152 additions and 17 deletions

View File

@@ -32,15 +32,18 @@ app.post('/api/crawler/notify', (req, res) => {
res.json({ ok: true })
})
// 生产环境:提供前端静态文件
// 生产环境:提供前端静态文件(含修订页 /edit依赖 SPA fallback
const distPath = path.join(__dirname, '..', 'dist')
if (fs.existsSync(distPath)) {
app.use(express.static(distPath))
// 非 API/WS 的请求一律返回 index.html由前端路由处理 /、/edit、/db 等
app.get('*', (req, res, next) => {
if (!req.path.startsWith('/api') && req.path !== '/ws') {
res.sendFile(path.join(distPath, 'index.html'))
} else next()
})
} else {
console.warn('[server] dist 目录不存在,前端页面(含 /edit 修订页)不可用。请在项目根目录执行 npm run build 后再启动。')
}
const server = http.createServer(app)