-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
124 lines (91 loc) · 3.16 KB
/
index.js
File metadata and controls
124 lines (91 loc) · 3.16 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
require('dotenv').config();
const express = require('express');
const env = require('./config/environment');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const path = require('path');
const app = express();
// const User = require('./models/user');
const port = 8000;
const expressLayouts = require('express-ejs-layouts');
const db = require('./config/mongoose');
// chage code
const cors = require('cors');
// used for session cookie
const session = require('express-session');
const passport = require('passport');
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 MongoStore = require('connect-mongo');
const flash = require('connect-flash');
const customMware = require('./config/middleware');
// setup the chat server to be used with socket.io
const chatServer = require('http').Server(app);
const chatSockets = require('./config/chat_sockets').chatSockets(chatServer);
// Allow requests from http://localhost:8000
const corsOptions = {
origin: 'http://localhost:8000',
};
app.use(cors(corsOptions));
chatServer.listen(5000);
console.log('chat server is listening on port 5000');
// const path = require('path');
// const sassMiddleware = require('sass-middleware');
// app.use(sassMiddleware({
// src: './assets/scss',
// dest: './assets/css',
// debug: true,
// outputStyle: 'extended',
// prefix: '/css'
// }));
app.use(express.urlencoded());
app.use(cookieParser());
// app.use(express.static(path.join(__dirname, 'assets')));
app.use(express.static(path.join(__dirname, env.asset_path)));
// app.use(express.static('./assets'));
//make the uploads path available to the browser
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 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');
// 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',
secret: env.session_cookie_key,
saveUninitialized: false,
resave: false,
store: new MongoStore({
mongoUrl: 'mongodb://0.0.0.0:27017/codeial_development',
// mongooseConnection: db,
// autoRemove: 'disabled'
},
function(err){
console.log(err || 'connect-mongodb setup ok');
},
),
cookie: {
maxAge: (100 * 60 * 100)
}
}));
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 the server: ${err}`);
}
console.log(`Server is running on port: ${port}`);
});