-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
41 lines (32 loc) · 988 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import dotenv from 'dotenv'
import express from 'express'
import fs from 'fs'
import routesConfig from './src/config/routes.js'
import { AuthController } from './src/controllers/auth.controller.js'
import { connectDB } from './src/config/db.js'
import { createServer } from 'http'
import { createSocket } from './src/config/socket.js'
import cors from 'cors'
dotenv.config()
const app = express()
const PORT = process.env.PORT || 3000
const dir = './public/uploads'
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true })
}
app.use(cors())
app.use(express.json())
app.use('/uploads', express.static('public/uploads'))
routesConfig.forEach(route => {
if (route.private) {
app.use(route.path, AuthController.authMiddleware, route.router)
} else {
app.use(route.path, route.router)
}
})
const httpServer = createServer(app)
connectDB()
createSocket(httpServer)
httpServer.listen(PORT, () => {
console.log(`App is running on http://localhost:${PORT}`)
})