工具完成
This commit is contained in:
32
server/index.js
Normal file
32
server/index.js
Normal file
@ -0,0 +1,32 @@
|
||||
const express = require('express')
|
||||
const cors = require('cors')
|
||||
const path = require('path')
|
||||
|
||||
const app = express()
|
||||
const PORT = process.env.PORT || 3001
|
||||
|
||||
// 中间件
|
||||
app.use(cors())
|
||||
app.use(express.json())
|
||||
app.use(express.urlencoded({ extended: true }))
|
||||
|
||||
// 静态文件服务
|
||||
app.use(express.static(path.join(__dirname, '../dist')))
|
||||
|
||||
// API路由
|
||||
app.use('/api', require('./routes/api'))
|
||||
|
||||
// 健康检查
|
||||
app.get('/health', (req, res) => {
|
||||
res.json({ status: 'ok', timestamp: new Date().toISOString() })
|
||||
})
|
||||
|
||||
// 处理Vue Router的历史模式
|
||||
app.get('*', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, '../dist/index.html'))
|
||||
})
|
||||
|
||||
// 启动服务器
|
||||
app.listen(PORT, () => {
|
||||
console.log(`服务器运行在 http://localhost:${PORT}`)
|
||||
})
|
Reference in New Issue
Block a user