parent
285bcf0f92
commit
1c143b8e77
@ -0,0 +1,26 @@
|
||||
const express = require('express');
|
||||
const path = require('path');
|
||||
const bodyParser = require('body-parser');
|
||||
const router = require('./router');
|
||||
const app = express();
|
||||
|
||||
// 中间件
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
|
||||
// API 路由
|
||||
app.use('/api', router);
|
||||
|
||||
// 静态文件
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
|
||||
// 处理 SPA 路由
|
||||
app.get('*', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'public', 'index.html'));
|
||||
});
|
||||
|
||||
// 启动服务器
|
||||
const PORT = process.env.PORT || 3000;
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server running on port ${PORT}`);
|
||||
});
|
Loading…
Reference in new issue