forked from cozuya/secret-hitler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
47 lines (42 loc) · 1.46 KB
/
app.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
'use strict';
const fs = require('fs'),
express = require('express'),
logger = require('morgan'),
cookieParser = require('cookie-parser'),
bodyParser = require('body-parser'),
favicon = require('serve-favicon'),
socketSession = require('express-socket.io-session'),
passport = require('passport'),
mongoose = require('mongoose'),
compression = require('compression'),
Strategy = require('passport-local').Strategy,
Account = require('./models/account'),
routesIndex = require('./routes/index'),
session = require('express-session')({
secret: 'hunter2',
resave: false,
saveUninitialized: false
}),
logFile = fs.createWriteStream('./logs/express.log', {flags: 'a'});
app.set('views', `${__dirname}/views`);
app.set('view engine', 'pug');
app.locals.pretty = true;
app.use(compression());
app.use(logger('combined', {stream: logFile}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(favicon(`${__dirname}/public/favicon.ico`));
app.use(cookieParser());
app.use(express.static(`${__dirname}/public`, {maxAge: 86400000 * 28}));
app.use(session);
io.use(socketSession(session, {
autoSave: true
}));
app.use(passport.initialize());
app.use(passport.session());
passport.use(new Strategy(Account.authenticate()));
passport.serializeUser(Account.serializeUser());
passport.deserializeUser(Account.deserializeUser());
mongoose.connect('mongodb://localhost/secret-hitler-app'); // local
mongoose.Promise = global.Promise;
routesIndex();