-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
114 lines (96 loc) · 3.24 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
110
111
112
113
114
/**
* Module dependencies.
*/
require( './models/offer');
require('./models/user');//for mongoose. Require this first!!!
var express = require('express')
, routes = require('./routes')
, http = require('http')
, path = require('path')
, mongoose = require('mongoose')
, passport = require('passport')
, FacebookStrategy = require('passport-facebook').Strategy
, config = require('./oauth.js');
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3333); // Sets the port number
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
app.use(require('stylus').middleware(__dirname + '/public'));
app.use(express.static(path.join(__dirname, 'public')));
});
passport.use(new FacebookStrategy({
clientID: config.facebook.clientID,
clientSecret: config.facebook.clientSecret,
callbackURL: config.facebook.callbackURL
}, function(accessToken, refreshToken, profile, done) {
process.nextTick(function() {
//Assuming user exists
done(null, profile);
});
}));
// Here we find an appropriate database to connect to, defaulting to
// localhost if we don't find one.
var uristring =
process.env.MONGOLAB_URI ||
'mongodb://heroku_app22855319:[email protected]:33559/heroku_app22855319'
process.env.MONGOHQ_URL ||
'mongodb://localhost/dinex_db';
// Makes connection asynchronously. Mongoose will queue up database
// operations and release them when the connection is complete.
mongoose.connect(uristring, function (err, res) {
if (err) {
console.log ('ERROR connecting to: ' + uristring + '. ' + err);
} else {
console.log ('Succeeded connected to: ' + uristring);
}
});
app.configure('development', function(){
app.use(express.errorHandler());
});
// Specifies Routes
app.get('/', routes.splash);
app.get('/newsfeed',routes.newsfeed);
app.get('/new',routes.create_form);
app.get('/offer/:id',routes.show_offer);
app.get('/status/:id',routes.show_status);
app.get('/purchase_status/:id',routes.show_pstatus)
app.get('/dashboard/:id',routes.user_dashboard);
app.get('/logout',routes.logout);
app.get('/success',routes.login_success);
//Error Routes
app.get('/error',routes.login_error);
app.get('/404',routes.page_error);
//Facebook Login
app.get('/auth/facebook', passport.authenticate('facebook'));
app.get('/auth/facebook/callback', passport.authenticate('facebook', {
successRedirect: '/success',
failureRedirect: '/error'
}));
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(obj, done) {
done(null, obj);
});
//Venmo Payments
app.get('/venmo', routes.venmo);
//Create Routes
app.post('/create', routes.create);
app.post('/create_user',routes.create_user);
//Update Route
app.get('/edit/:id',routes.get_edit_form);
app.post('/update/:id',routes.update_offer)
//Delete Route
app.get('/delete/:id', routes.delete_offer);
// Specifies address on localhost
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});