-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
145 lines (124 loc) · 4.47 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
require('dotenv').load();
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const passport = require('./routes/passport');
const utils = require('./utils');
const greenspace = require('./routes/greenspace');
const review = require('./routes/review');
const event = require('./routes/event');
const user = require('./routes/user');
const tag = require('./routes/tag');
const discover = require('./routes/discover');
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGODB_URI || 'mongodb://127.0.0.1/greenspace', {
useMongoClient: true,
});
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
const app = express();
// Serve static assets from the public folder in project root
app.use(express.static('public'));
// Set up some middleware to use.
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(bodyParser());
// set up sessions
app.use(session({
secret: 'session-secret',
resave: 'false',
saveUninitialized: 'true'
}));
// hook up passport
app.use(passport.initialize());
app.use(passport.session());
// authentication routes
app.get('/auth/facebook', passport.authenticate('facebook'));
app.get(
'/auth/facebook/callback',
passport.authenticate(
'facebook',
{ failureRedirect: '/' }
),
function(req, res) {
res.redirect(process.env.BASE_URL + '/loading');
}
);
if (process.env.TEST) {
app.use((req, res, next) => {
req.user = {_id: '5a63c29174d39b08342a59e2',
fbid: 10211342727149288,
displayname: 'Gabrielle Rivera',
photo: 'https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/15590502_10208201639144052_5928782208183143104_n.jpg?oh=07a9b95b86ef0d984b4f42928a4f2568&oe=5AEF5901',
__v: 0 };
next();
});
app.use('/event/join/*', (req, res, next) => {
req.user = { _id: '5a63c29174d39b08342a1038',
fbid: 10211342727149298,
displayname: 'Chicken Joe',
photo: 'https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/15590502_10208201639144052_5928782208183143104_n.jpg?oh=07a9b95b86ef0d984b4f42928a4f2568&oe=5AEF5901',
};
next();
});
app.use('/event/leave/*', (req, res, next) => {
req.user = { _id: '5a63c29174d39b08342a1038',
fbid: 10211342727149298,
displayname: 'Chicken Joe',
photo: 'https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/15590502_10208201639144052_5928782208183143104_n.jpg?oh=07a9b95b86ef0d984b4f42928a4f2568&oe=5AEF5901',
};
next();
});
app.use('/event/user/pending', (req, res, next) => {
req.user = { _id: '5a63c29174d39b08342a5969',
fbid: 10211342727149269,
displayname: 'Cody Maverick',
photo: 'https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/15590502_10208201639144052_5928782208183143104_n.jpg?oh=07a9b95b86ef0d984b4f42928a4f2568&oe=5AEF5901',
};
next();
});
app.use('/event/accept/*', (req, res, next) => {
req.user = { _id: '5a63c29174d39b08342a5420',
fbid: 10211342727149420,
displayname: 'Tank Evans',
photo: 'https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/15590502_10208201639144052_5928782208183143104_n.jpg?oh=07a9b95b86ef0d984b4f42928a4f2568&oe=5AEF5901',
};
next();
});
app.use('/event/decline/*', (req, res, next) => {
req.user = { _id: '5a63c29174d39b08342a5969',
fbid: 10211342727149269,
displayname: 'Cody Maverick',
photo: 'https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/15590502_10208201639144052_5928782208183143104_n.jpg?oh=07a9b95b86ef0d984b4f42928a4f2568&oe=5AEF5901',
};
next();
});
}
app.get('/logout', (req, res) => {
req.logout();
res.redirect(process.env.BASE_URL + '/');
});
// Set up authentication
app.post('*', utils.requireAuthentication);
app.put('*', utils.requireAuthentication);
app.delete('*', utils.requireAuthentication);
// Set up our routes.
app.use('/greenspace', greenspace);
app.use('/review', review);
app.use('/event', event);
app.use('/user', user);
app.use('/tag', tag);
app.use('/discover', discover);
// Auto direct to homepage
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'public/index.html'));
});
// Open app on specified port (default 3000)
app.listen(process.env.PORT || 3000, () => {
console.log("Listening on port 3000");
});
// Export our app (so that tests and bin can find it)
module.exports = app;