forked from Learn-by-doing/bitstarter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (37 loc) · 1.01 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
var express = require('express');
var session = require('express-session');
var config = require('./config.js');
var MySQLStore = require('express-mysql-session')(session);
var sessionStore = new MySQLStore(config.dbOptions);
var exphbr = require('express-handlebars');
var bodyParser = require('body-parser');
var serveStatic = require('serve-static');
var app = express();
app.engine('html', exphbr({
defaultLayout: 'main',
extname: '.html'
}));
app.use(session({
key: 'bitstarter-cookie',
secret: 'secret!',
store: sessionStore,
resave: false,
saveUninitialized: true
}));
app.use(function(req, res, next) {
req.isAuthenticated = function() {
return !!req.session.user;
};
next();
});
app.use(function(req, res, next) {
console.log('URL requested', req.originalUrl);
next();
});
app.set('view engine', 'html');
app.use(serveStatic(__dirname + '/public'));
app.config = require('./config');
require('./controllers')(app);
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});