kun-galgame-vue/server/index.js

41 lines
1,009 B
JavaScript
Raw Normal View History

const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
const app = express()
// 使用cors中间件来允许跨域请求
app.use(cors())
app.use(bodyParser.json())
const port = 10007 // 端口号
2023-06-02 14:24:57 +00:00
// 用户路由
const userRoutes = require('./routes/user')
2023-05-30 08:13:59 +00:00
2023-06-02 14:24:57 +00:00
// 帖子路由
const topicRoutes = require('./routes/topic')
2023-06-02 14:24:57 +00:00
// 登录路由
const loginRoutes = require('./routes/login')
2023-06-02 14:24:57 +00:00
// 注册路由
const registerRoutes = require('./routes/register')
2023-05-30 08:13:59 +00:00
2023-06-07 14:16:33 +00:00
// 上传图片路由
const uploadImagesRoutes = require('./routes/upload-image')
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)
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}`)
})