-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (40 loc) · 1014 Bytes
/
index.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
42
43
44
45
46
47
48
require('dotenv').config()
// Import Dependencies
const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
const cookieParser = require('cookie-parser')
const session = require('express-session')
// Import File
const appRouters = require('./app/routes/index')
const app = express()
app.use(cors())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(cookieParser())
app.use(
session({
secret: process.env.SECRET_KEY,
resave: true,
saveUninitialized: true,
cookie: { maxAge: 3600000 } // 1 hr
})
)
// Set route
app.use('/api/v1', appRouters)
// Catch & Handle Error
// Error 404
app.use((req, res, next) => {
const err = new Error('Not Found')
err.status = 404
next(err)
})
// Error 500 & other
app.use((err, req, res) => {
res.status(err.status || 500)
res.render('error', {
message: err.message,
error: err
})
})
app.listen(process.env.PORT)