forked from rlr/noodleapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
73 lines (59 loc) · 1.81 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
'use strict';
var express = require('express');
var configurations = module.exports;
var app = express();
var server = require('http').createServer(app);
var nconf = require('nconf');
var settings = require('./settings')(app, configurations, express);
var passport = require('passport');
var redis = require('redis');
var client = redis.createClient();
var AppDotNetStrategy = require('passport-appdotnet').Strategy;
var noodle = require('./package');
var utils = require('./lib/utils');
var userDb = require('./lib/user');
nconf.argv().env().file({ file: 'local.json' });
/* Passport OAuth setup */
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(obj, done) {
done(null, obj);
});
passport.use(new AppDotNetStrategy({
clientID: nconf.get('appnet_consumer_key'),
clientSecret: nconf.get('appnet_consumer_secret'),
scope: 'stream messages write_post follow',
callbackURL: nconf.get('domain') + ':' + nconf.get('authPort') + '/auth/appdotnet/callback'
},
function(accessToken, refreshToken, profile, done) {
process.nextTick(function (err) {
if (!profile.access_token) {
profile.access_token = accessToken;
}
return done(err, profile);
});
}
));
/* Filters for routes */
var isLoggedIn = function(req, res, next) {
if (req.session.passport.user) {
next();
} else {
res.redirect('/');
}
};
/* Routing setup */
require('./routes')(app, client, isLoggedIn, noodle, nconf);
require('./routes/auth')(app, passport);
app.get('/404', function(req, res, next){
next();
});
app.get('/403', function(req, res, next){
err.status = 403;
next(new Error('not allowed!'));
});
app.get('/500', function(req, res, next){
next(new Error('something went wrong!'));
});
server.listen(process.env.PORT || nconf.get('port'));