-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
53 lines (47 loc) · 1.71 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
49
50
51
52
53
const express = require('express');
const bodyParser = require('body-parser');
const ejs = require('ejs');
const http = require('http');
const cookieParser = require('cookie-parser');
const validator = require('express-validator');
const session = require('express-session');
const MongoStore = require('connect-mongo')(session);
const mongoose = require('mongoose');
const flash = require('connect-flash');
const passport = require('passport');
const container = require('./container');
container.resolve(function(users, _) {
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost:27017/footballkik', { useMongoClient: true });
const app = SetupExpress();
function SetupExpress() {
const app = express();
const server = http.createServer(app);
server.listen(3000, function() {
console.log('Listening on port 3000');
});
ConfigureExpress(app);
const router = require('express-promise-router')();
users.SetRouting(router);
app.use(router);
}
function ConfigureExpress(app) {
require('./passport/passport-local');
app.use(express.static('public'));
app.use(cookieParser());
app.set('view engine', 'ejs');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(validator());
app.use(session({
secret: 'thisisasecretkey',
resave: true,
saveInitialized: true,
store: new MongoStore({ mongooseConnection: mongoose.connection })
}));
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
app.locals._ = _;
}
});