-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
39 lines (30 loc) · 1.12 KB
/
Copy pathapp.js
File metadata and controls
39 lines (30 loc) · 1.12 KB
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
import dotenv from 'dotenv'
import express from 'express'
import connectDB from './DB/connection.js'
import authRouter from './src/modules/auth/auth.routes.js'
import userRouter from './src/modules/user/user.routes.js'
import postRouter from './src/modules/post/post.routes.js'
import cors from 'cors'
import { cleanLoggedOutTokens } from './src/utils/cleanLogoutDB.js'
import { GlobalErrorHandling } from './src/utils/errorHandling.js'
dotenv.config()
const app = express()
const port = process.env.PORT
const BASE_URL = process.env.BASE_URL
// Global Middlewares
app.use(cors())
app.use(express.json())
app.use(`${BASE_URL}/uploads`, express.static('./uploads'))
// Routing
app.use(`${BASE_URL}/auth`, authRouter)
app.use(`${BASE_URL}/users`, userRouter)
app.use(`${BASE_URL}/posts`, postRouter)
// all() does NOT support nested routing as use()
app.all('*', (req, res, next) => res.json({ message: '404 Page Not Found' }))
// Global Error Handling
app.use(GlobalErrorHandling)
// Init Functions
connectDB()
cleanLoggedOutTokens()
// Server Boot
app.listen(port, () => console.log(`Server Booting...\nServer Listening on PORT::${port}!`))