-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (43 loc) · 1.38 KB
/
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
40
41
42
43
44
45
46
47
48
// setup
require('dotenv').config()
const express = require('express')
const app = express()
const port = 8080
const expressLayouts = require('express-ejs-layouts')
const methodOverride = require('method-override')
const session = require('express-session')
const setCurrentUser = require('./middlewares/set_current_user')
const ensureLoggedIn = require('./middlewares/ensure_logged_in')
// initialise
app.set('view engine', 'ejs')
app.use(expressLayouts)
app.use(express.static('public'))
app.use(methodOverride('_method'))
app.use(express.urlencoded())
app.use(session({
cookie: { maxAge: 1000 * 60 * 60 * 24 * 3 }, // approx 3 days
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: true
}))
// define routers
const homeRouter = require('./routes/home_router')
const sessionRouter = require('./routes/session_router')
const tripRouter = require('./routes/trip_router')
const activityRouter = require('./routes/activity_router')
const categoryRouter = require('./routes/category_router')
const userRouter = require('./routes/user_router')
// use routes and middlewares
app.use(setCurrentUser)
app.use(homeRouter)
app.use(sessionRouter)
app.use(userRouter)
app.use(ensureLoggedIn)
app.use(tripRouter)
app.use(activityRouter)
app.use(categoryRouter)
// app.use(bucketlistRouter)
// listen on port
app.listen(port, () => {
console.log(`ready to travel from port ${port}`);
})