feat: add backend server
This commit is contained in:
26
server/index.js
Normal file
26
server/index.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import dotenv from 'dotenv'
|
||||
dotenv.config()
|
||||
|
||||
// 连接数据库
|
||||
import connectDB from './database.js'
|
||||
await connectDB()
|
||||
|
||||
import express from 'express'
|
||||
import { userRouter } from './controller/user.js'
|
||||
import { stabilityRouter } from './controller/stability.js'
|
||||
import { standardRouter } from './controller/standard.js'
|
||||
|
||||
const app = express()
|
||||
app.use(express.json())
|
||||
|
||||
// 注册路由
|
||||
app.use('/api/user', userRouter)
|
||||
app.use('/api/stability', stabilityRouter)
|
||||
app.use('/api/standard', standardRouter)
|
||||
|
||||
// 从环境变量中读取端口号,如果环境变量中没有指定端口号,则使用默认的端口号
|
||||
const PORT = process.env.PORT || 5000
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server is running on http://localhost:${PORT}`)
|
||||
})
|
||||
Reference in New Issue
Block a user