-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
108 lines (77 loc) · 2.61 KB
/
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
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
//using express framework
const express = require('express');
const app = express();
//defining port where application gonna run
const port = 8000;
//helps in parsing cookies from browser
const cookieParser = require('cookie-parser');
//using ejs --> embedded javascript
const expressLayouts = require('express-ejs-layouts');
//creating login session and authentication using passport js
const session = require('express-session');
const passport = require('passport');
const passportLocal = require('./config/passport-local-strategy');
//creating jwt authentication for api calls passport jwt strategy
const passportJwt =require('./config/passport-jwt-strategy');
//creating google authentication
const passportGoogle = require('./config/passport-google-oauth-strategy');
//setting up mongods database using mongoose
const db = require('./config/mongoose');
const MongoStore = require('connect-mongodb-session')(session);
//css styling using scss
const saasMiddleware = require ('node-sass-middleware');
//flash for notifications
const flash = require('connect-flash');
const customMware = require('./config/middleware')
app.use(saasMiddleware(
{
src:'./assets/scss',
dest:'./assets/css',
debug:true,
outputStyle:'extended',
prefix:'/css'
}
))
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
//making files globally available for server to acess
app.use(express.static('./assets'));
app.use('/uploads',express.static(__dirname+'/uploads'))
//extract style and script from sub pages into layout--> concept of layout and partials
app.use(expressLayouts);
app.set('layout extractStyles', true);
app.set('layout extractScripts', true)
app.set('view engine', 'ejs');
app.set('views', './views');
//mongo store is used too store the session cookie in the database
app.use(session({
name: 'codial',
//TODO change the secret before deployment in production mode
secret: 'blahblah',
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');
})
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(passport.setAuthenticatedUser);
app.use(flash());
app.use(customMware.setFlash);
//use express Router
app.use('/', require('./routes'));
app.listen(port, function (err) {
if (err) {
console.log(`Error in running server: ${err}`);
}
console.log(`server is running on : ${port}`);
})