You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
634 B
27 lines
634 B
2 months ago
|
const express = require('express');
|
||
2 months ago
|
const path = require('path');
|
||
2 months ago
|
const bodyParser = require('body-parser');
|
||
2 months ago
|
const router = require('./router');
|
||
|
const app = express();
|
||
2 months ago
|
|
||
|
// 中间件
|
||
|
app.use(bodyParser.json());
|
||
|
app.use(bodyParser.urlencoded({ extended: true }));
|
||
|
|
||
2 months ago
|
// 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'));
|
||
|
});
|
||
2 months ago
|
|
||
2 months ago
|
// 启动服务器
|
||
2 months ago
|
const PORT = process.env.PORT || 3000;
|
||
|
app.listen(PORT, () => {
|
||
|
console.log(`Server running on port ${PORT}`);
|
||
|
});
|