-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
114 lines (88 loc) · 2.76 KB
/
index.js
File metadata and controls
114 lines (88 loc) · 2.76 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// require express
const express = require('express');
// cookie-parser
const cookieParser = require('cookie-parser');
const app = express();
// define port
const port = 8000;
// express layout library
const expressLayouts = require('express-ejs-layouts');
// require mongoose
const db = require('./config/mongoose')
// import express-session which is used for session cookie
const session = require('express-session')
// import Passport
const passport = require('passport')
// import strategy
const passportLocal = require('./config/passport-local-strategy')
// import mongo-store
const MongoStore = require('connect-mongo');
// import SASS
const sassMiddleware = require('node-sass-middleware');
app.use(sassMiddleware({
src: './assets/scss',
dest: './assets/css',
debug: true,
outputStyle: 'extended',
prefix: '/css'
}))
// app.use(session({
// secret: 'foo',
// store: MongoStore.create(db)
// }))
// reading through the POST request
app.use(express.urlencoded());
// setting up the cookie-parser
app.use(cookieParser());
// tell node to include link tag in the header section
// extract style and scripts from sub pages into the layout
app.set('layout extractStyles', true);
app.set('layout extractScripts', true);
// Static files
app.use(express.static('./assets'));
// use the library
app.use(expressLayouts);
// setup the view engine
app.set('view engine', 'ejs');
app.set('views', './views');
// add a middleware which takes in the session cookie and encrypts it
// mongo store is used to store the session cookie in the db
// app.use(session({
// name: 'codeial',
// // TODO change the secret before deployment in production mode
// secret: "blahsomething",
// saveUninitialized: false,
// resave: false,
// cookie: {
// maxAge: (1000 * 60 * 100)
// },
// store: new MongoStore({
// mongooseConnection: db,
// autoRemove: 'disabled'
// },
// function(err){
// console.log(err || 'connect-mongodb setup ok');
// })
// }));
// setting up mongo store
app.use(session({
secret: 'shhhhhhhhhhhhhhht',
resave: false,
saveUninitialized: true,
store: MongoStore.create({
mongoUrl: 'mongodb://localhost/codeial_development',
})
}))
// we need to tell the app to use passport
app.use(passport.initialize());
app.use(passport.session());
// - This function gets called after the passport is initialised to check whether a session cookie is present or not. This function is automatically called as a middleware
app.use(passport.setAuthenticatedUser);
// use express router
app.use('/', require('./routes'));
app.listen(port, function(err){
if(err){
console.log(`Error in running the server: ${err}`);
}
console.log(`Server is running on port: ${port}`);
})