Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
158 lines (91 loc) · 3.44 KB
/
Copy pathindex.js
File metadata and controls
158 lines (91 loc) · 3.44 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
const express = require('express');
const env = require('./config/environment');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const app = express();
require('./config/view-helpers')(app);
const port = 8000;
const expressLayouts = require('express-ejs-layouts');
//When I start my server, it will require all these things. While requiring my Mongoose file, it will go and run mongoose.js part
const db = require('./config/mongoose');
//Used for session cookie
const session = require('express-session');
const passport = require('passport');
//File for passport local strategy
const passportLocal = require('./config/passport-local-strategy');
const passportJWT = require('./config/passport-jwt-strategy');
const passportGoogle = require('./config/passport-google-oauth2-strategy');
const MongoStore = require('connect-mongo')(session);
const sassMiddleware = require('node-sass-middleware');
//Set it up to be used
const flash = require('connect-flash');
const customMware = require('./config/middleware');
//Set up the chat server to be used with socket.io
const chatServer = require('http').Server(app);
//This is going to out file
//Function is going to be used over here
const chatSockets = require('./config/chat_sockets').chatSockets(chatServer);
chatServer.listen(5000);
console.log('Chat Server is listening on Port 5000');
const path = require('path');
//In the production mode, it shouldn't be running sassMiddleware everytime
if (env.name == 'development'){
app.use(sassMiddleware({
src: path.join(__dirname,env.asset_path,'scss'),
dest: path.join(__dirname,env.asset_path,'css'),
debug: true,
outputStyle: 'extended',
prefix: '/css'
}));
}
app.use(express.urlencoded({extended:false}));
app.use(cookieParser());
//In which folder should the app lookout for Static files
app.use(express.static(env.asset_path));
// make the uploads path available to the browser
// codeial/uploads is available on /uploads path now
app.use('/uploads',express.static(__dirname + '/uploads'));
app.use(logger(env.morgan.mode, env.morgan.options));
app.use(expressLayouts);
//Extract style and scripts from sub pages into the layout
app.set('layout extractStyles',true);
app.set('layout extractScripts',true);
//Set Up The View Engine
app.set('view engine', 'ejs');
app.set('views', './views');
//MongoStore is used to store the session cookie in the Database
app.use(session({
name: 'codeial',
//ToDo Change the secret before deployment in production mode
secret: env.session_cookie_key,
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);
//This uses Session cookie, the flash msgs will be set up in cookies which store session information
app.use(flash());
app.use(customMware.setFlash);
//Use express router
app.use('/', require('./routes/index'));
app.use(express.static(__dirname + '/public'));
app.listen(port, function(err){
if (err)
{
console.log(`Error in running the server: ${err}`);
}
console.log(`Server is running on port: ${port}`);
});