-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (29 loc) · 983 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
import express, { json, urlencoded } from 'express'
import morgan from 'morgan'
import cors from 'cors'
import connectDB from './config/db.js'
import { signin, signup, protect } from './utils/auth.js'
import flimRouter from './resources/flim/flim.router.js'
import userRouter from './resources/user/user.router.js'
import scriptRouter from './resources/script/script.router.js'
const app = express()
if (process.env.NODE_ENV === `development`) {
app.use(morgan('dev'))
}
app.disable('x-powered-by')
app.use(cors())
app.use(urlencoded({ extended: false }))
app.use(json())
app.post('/signup', signup)
app.post('/signin', signin)
app.use('/api', protect)
app.use('/api/flim', flimRouter)
app.use('/api/user', userRouter)
app.use('/api/script', scriptRouter)
const PORT = process.env.PORT || 3000
try {
await connectDB()
app.listen(PORT, console.log(`Server running in ${ process.env.NODE_ENV }mode on port ${ PORT }`))
} catch (error) {
console.error(error)
}