-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
60 lines (47 loc) · 1.45 KB
/
app.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
49
50
51
52
53
54
55
56
57
58
59
60
// External Dependencies
const express = require('express')
const mongoose = require('mongoose')
const dotenv = require('dotenv')
const path = require('path')
const cookieParser = require('cookie-parser')
const moment = require('moment')
const morgan = require('morgan')
// Internal Dependencies:
const {
notFoundHandler,
errorHandler,
} = require('./middlewares/common/errorHandler')
const authRouter = require('./router/authRouter')
const foodRouter = require('./router/foodRouter')
const publicRouter = require('./router/publicRouter')
const { mongooseConnection } = require('./config/db')
// Express Setup:
const app = express()
dotenv.config()
// Moment Set as application local for ejs engine:
app.locals.moment = moment
// Database Connection
mongooseConnection()
// Request Parser
app.use(morgan('dev'))
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
// Set View Engine
app.set('view engine', 'ejs')
// Set Static Folder
app.use(express.static(path.join(__dirname, 'public')))
// Parse Cookie Data
app.use(cookieParser(process.env.COOKIE_SECRET))
// Routing Setup
app.use('/', publicRouter)
app.use('/auth', authRouter)
app.use('/food', foodRouter)
// Health Check
app.get('/health', (req, res) => res.status(200).json({ status: 'ok' }))
// Not Found Handler
app.use(notFoundHandler)
// Error Handler
app.use(errorHandler)
app.listen(process.env.PORT, () => {
console.log(`Application listening to port ${process.env.PORT}`)
})