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

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}`);
});