kun-galgame-vue/project/server/index.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

const express = require('express')
2023-06-14 09:48:02 +00:00
const path = require('path')
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, '.')
// 使用cors中间件来允许跨域请求
app.use(cors())
app.use(bodyParser.json())
2023-06-14 09:48:02 +00:00
app.use(express.static(staticPath))
2023-08-27 17:11:39 +00:00
const port = 10008 // 端口号
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-08-19 10:10:37 +00:00
// 话题路由
2023-06-14 09:48:02 +00:00
const topicRoutes = require('./src/routes/topic')
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 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)
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}`)
})