forked from kenbolton/meetdownjs
-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.js
109 lines (96 loc) · 2.63 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*jshint laxcomma:true */
/**
* Module dependencies.
*/
var express = require('express')
, http = require('http')
, path = require('path')
, mongo = require('mongodb')
, hbs = require('hbs')
, moment = require('moment')
, routes = require('./routes')
, users = require('./routes/users')
, events = require('./routes/events')
, auth = require('./lib/auth');
var app = express();
app.configure('development', function () {
var db = mongo.Db('test', mongo.Server('localhost', 27017, {}), {});
app.set('db', db);
});
app.configure('stage', function () {
var db = mongo.Db('test', mongo.Server('localhost', 27017, {}), {});
app.set('db', db);
app.set('trust proxy', true);
});
app.configure(function () {
app.get('db').open(function () {});
});
app.configure('development', function () {
app.use(auth.configuration(__dirname + '/settings_testing', {
debug: true,
saveUser: function (githubUserMetadata) {
// TODO: save to database???
app.get('db').collection('users', function (error, users) {
if (error) { return new Error(error); }
users.save({
email: githubUserMetadata.email,
github_id: githubUserMetadata.id,
github_login: githubUserMetadata.login
}, function (error, doc) {
var id = doc._id;
});
});
console.log(githubUserMetadata);
}
}));
});
app.configure('development', function () {
app.use(express.logger('dev'));
});
// Configuration
app.configure(function () {
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'hbs');
app.use(express.favicon());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({ secret: "SUPERSECRETKEY" }));
app.use(auth.middleware());
app.use(function (req, res, next) {
if (req.session.auth) {
res.locals.user_name = req.session.auth.github.user.name;
}
next();
});
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.configure('development', function () {
app.use(express.errorHandler());
});
hbs.registerHelper('date', function (format, date) {
return date ? moment(date).format(format) : '';
});
// Routes
app.get('/', routes.home);
app.post('/my/events',
users.findOne,
events.findOne,
events.update
);
app.get('/events/create',
events.create
);
app.get('/events',
events.list
);
app.post('/events',
events.dateify,
events.collect,
events.save
);
http.createServer(app).listen(app.get('port'), function () {
console.log("Express server listening on port " + app.get('port'));
});