2023-05-29 05:22:36 +00:00
|
|
|
const express = require('express')
|
2023-06-14 09:48:02 +00:00
|
|
|
const path = require('path')
|
2023-05-29 05:22:36 +00:00
|
|
|
const cors = require('cors')
|
|
|
|
const bodyParser = require('body-parser')
|
|
|
|
const app = express()
|
2023-06-14 09:48:02 +00:00
|
|
|
const staticPath = path.join(__dirname, '.')
|
2023-05-29 05:22:36 +00:00
|
|
|
|
|
|
|
// 使用cors中间件来允许跨域请求
|
|
|
|
app.use(cors())
|
|
|
|
app.use(bodyParser.json())
|
2023-06-14 09:48:02 +00:00
|
|
|
app.use(express.static(staticPath))
|
2023-05-29 05:22:36 +00:00
|
|
|
|
2023-06-01 07:40:03 +00:00
|
|
|
const port = 10007 // 端口号
|
2023-05-29 05:22:36 +00:00
|
|
|
|
2023-06-02 14:24:57 +00:00
|
|
|
// 用户路由
|
2023-06-14 09:48:02 +00:00
|
|
|
const userRoutes = require('./src/routes/user')
|
2023-05-30 08:13:59 +00:00
|
|
|
|
2023-06-02 14:24:57 +00:00
|
|
|
// 帖子路由
|
2023-06-14 09:48:02 +00:00
|
|
|
const topicRoutes = require('./src/routes/topic')
|
2023-06-02 13:53:58 +00:00
|
|
|
|
2023-06-02 14:24:57 +00:00
|
|
|
// 登录路由
|
2023-06-14 09:48:02 +00:00
|
|
|
const loginRoutes = require('./src/routes/login')
|
2023-06-02 13:53:58 +00:00
|
|
|
|
2023-06-02 14:24:57 +00:00
|
|
|
// 注册路由
|
2023-06-14 09:48:02 +00:00
|
|
|
const registerRoutes = require('./src/routes/register')
|
2023-05-30 08:13:59 +00:00
|
|
|
|
2023-06-07 14:16:33 +00:00
|
|
|
// 上传图片路由
|
2023-06-14 09:48:02 +00:00
|
|
|
const uploadImagesRoutes = require('./src/routes/upload-image')
|
2023-06-07 14:16:33 +00:00
|
|
|
|
2023-06-02 14:24:57 +00:00
|
|
|
app.use('/kungalgamer', userRoutes)
|
|
|
|
app.use('/topic', topicRoutes)
|
|
|
|
app.use('/login', loginRoutes)
|
|
|
|
app.use('/register', registerRoutes)
|
2023-06-07 14:16:33 +00:00
|
|
|
app.use('/upload', uploadImagesRoutes)
|
2023-05-29 05:22:36 +00:00
|
|
|
|
|
|
|
app.use((err, req, res, next) => {
|
|
|
|
console.error(err.stack)
|
|
|
|
res.status(500).json({ success: false, error: 'Internal Server Error' })
|
|
|
|
})
|
|
|
|
|
|
|
|
app.listen(port, '127.0.0.1', () => {
|
|
|
|
console.log(`Server is running on http://127.0.0.1:${port}`)
|
|
|
|
})
|