forked from yTakkar/React-Instagram-Clone-2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
66 lines (57 loc) · 1.43 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
61
62
63
64
65
66
/**
* @author Faiyaz Shaikh <[email protected]>
* GitHub repo: https://github.com/yTakkar/React-Instagram-Clone-2.0
*/
// MAIN ENTRY OF OUR APP
// Initializes dotenv
require('dotenv').config()
// Require Dependencies
const
express = require('express'),
app = express(),
{
env: { PORT, SESSION_SECRET_LETTER }
} = process,
{ rainbow } = require('handy-log'),
favicon = require('serve-favicon'),
{ join } = require('path'),
hbs = require('express-handlebars'),
bodyParser = require('body-parser'),
validator = require('express-validator'),
session = require('client-sessions'),
cookieParser = require('cookie-parser')
// Project Files
const { variables } = require('./config/Middlewares')
const AppRoutes = require('./app-routes')
// View engine
app.engine('hbs', hbs({
extname: 'hbs'
}))
app.set('view engine', 'hbs')
// Middlewares
app.use(favicon(
join(__dirname, '/dist/images/favicon/favicon.png')
))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
extended: false
}))
app.use(validator())
app.use(express.static(
join(__dirname, '/dist')
))
app.use(session({
cookieName: 'session',
secret: SESSION_SECRET_LETTER,
duration: 24 * 60 * 60 * 1000,
activeDuration: 5 * 60 * 1000
}))
app.use(cookieParser())
// Middleware for some local variables to be used in the template
app.use(variables)
// App routes
AppRoutes(app)
// Listening to PORT
app.listen(PORT, () =>
rainbow('App running..')
)