-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathapp.js
87 lines (77 loc) · 2.3 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
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
/**
* Module dependencies.
*/
var express = require('express'),
routes = require('./routes'),
http = require('http'),
path = require('path'),
passport = require('passport'),
LocalStrategy = require('passport-local').Strategy,
hbs = require('express3-handlebars'),
mongoose = require('mongoose'),
MongoStore = require('connect-mongo')(express),
config = require('./config/config.js');
// Connect to mongoose database and create object schemas
mongoose.connect(config.db);
var User = require('./models/user.js');
var Game = require('./models/game.js');
// Setup express server
var app = express();
app.engine('handlebars', hbs({defaultLayout: 'main'}));
app.set('port', config.port);
app.set('db', mongoose);
app.set('views', __dirname + '/views');
app.set('view engine', 'handlebars');
app.use(express.favicon());
app.use(express.static('public'));
app.use(express.logger('dev'));
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.session({secret: 'keyboard cat'}));
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
app.use(require('stylus').middleware({
src: __dirname + '/public/stylesheets',
// dest: __dirname + '/public/stylesheets',
compile: function (str, path, fn) {
stylus(str)
.set('filename', path)
.set('compress', true)
.render(fn);
}
}));
app.use(express.static(path.join(__dirname, 'public')));
passport.serializeUser(function(user, done) {
console.log('User serialize');
console.log(user);
console.log(user.email);
done(null, user.email);
});
passport.deserializeUser(function(email, done) {
console.log('User deserialize');
User.findOne({email: email}, function (err, user) {
done(err, user);
});
});
// Setup passport config
passport.use(new LocalStrategy({
usernameField: 'email',
passwordField: 'password'
},
function(username, password, done) {
User.login(username, password, function(err, user) {
// console.log(err, user);
return done(null, user);
});
})
);
require('./routes')(app);
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});