-
Notifications
You must be signed in to change notification settings - Fork 0
/
campuchia.js
80 lines (57 loc) · 2.19 KB
/
campuchia.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
"use strict";
console.log('App process id (pid): %s', process.pid);
var express = require('express');
var db = require('./lib/db');
var methodOverride = require('method-override');
var bodyParser = require('body-parser');
var path = require('path');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var resource = require('express-resource');
var assert = require('assert');
var app = express();
var config = require('./config/config.json')[app.get('env')];
db.connect(config.mongoUrl);
app.use('/', logger('combined', {immediate: true}));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(require('express-session')({
secret: 'keyboard cat',
resave: false,
saveUninitialized: false
}));
app.use(methodOverride(function(req, res) {
if (req.body && typeof req.body === 'object' && '_method' in req.body) {
// look in urlencoded POST bodies and delete it
var method = req.body._method;
delete req.body._method;
return method;
}
}));
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.static(path.join(__dirname, 'public')));
//Authenticate
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
var FacebookStrategy = require('passport-facebook').Strategy;
app.use(passport.initialize());
app.use(passport.session());
// passport config
var User = require('./models/user');
passport.use(new LocalStrategy(User.authenticate()));
passport.serializeUser(User.serializeUserSocialSupport());
passport.deserializeUser(User.deserializeUserSocialSupport());
passport.use(new GoogleStrategy(config.GoogleStrategy,User.socialAuthenticate('google')));
passport.use(new FacebookStrategy(config.FacebookStrategy,User.socialAuthenticate('facebook')));
var routes = require('./routes/index');
app.use('/', routes);
app.resource('groups', require('./routes/group')());
module.exports = app;
if (!module.parent) {
app.listen(config.port);
console.log('(%s) app listening on port %s', app.get('env'), config.port);
}