初始化:连锁餐饮数字化运营管理平台
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import 'dotenv/config'
|
||||
import express from 'express'
|
||||
import cors from 'cors'
|
||||
import { authMiddleware, AuthRequest } from './middleware/auth.js'
|
||||
import { errorHandler, notFoundHandler } from './middleware/error.js'
|
||||
import authRoutes from './routes/auth.js'
|
||||
import dataRoutes from './routes/data.js'
|
||||
import taskRoutes from './routes/tasks.js'
|
||||
|
||||
const app = express()
|
||||
const PORT = parseInt(process.env.PORT || '3001')
|
||||
|
||||
app.use(cors({
|
||||
origin: process.env.CLIENT_URL || 'http://localhost:5173',
|
||||
credentials: true,
|
||||
}))
|
||||
app.use(express.json())
|
||||
|
||||
app.get('/api/health', (req, res) => {
|
||||
res.json({ success: true, data: { status: 'ok', time: new Date().toISOString() } })
|
||||
})
|
||||
|
||||
app.use('/api/auth', authRoutes)
|
||||
|
||||
app.use((req, res, next) => {
|
||||
if (req.path === '/api/health' || req.path.startsWith('/api/auth')) {
|
||||
return next()
|
||||
}
|
||||
authMiddleware(req as AuthRequest, res, next)
|
||||
})
|
||||
|
||||
app.use('/api', dataRoutes)
|
||||
app.use('/api/tasks', taskRoutes)
|
||||
|
||||
app.use(notFoundHandler)
|
||||
app.use(errorHandler)
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server running on http://localhost:${PORT}`)
|
||||
})
|
||||
|
||||
export default app
|
||||
Reference in New Issue
Block a user