-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
43 lines (37 loc) · 1.09 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
// PACKAGES //
var express = require('express');
var bodyParser = require('body-parser');
// MODULES //
var chat = require('./modules/chat');
var data = require('./modules/data');
var graph = require('./modules/graph');
var config = require('./modules/config');
// APP SETUP //
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
// ENDPOINTS //
app.get('/', chat.verify);
app.post('/', function (req, res) {
chat.parseMessages(req.body, function (userId, message) {
console.log('callback on', userId, message);
data.getUser(userId, function (user) {
if (!user) chat.sendWelcome(userId);
else {
graph.getFriends(userId, function (friends) {
chat.sendMessage(userId, JSON.stringify(friends));
});
}
});
});
});
app.get('/auth', function (req, res) {
var userId = req.query.userId;
var code = req.query.code;
res.send('got id ' + userId + ' with code ' + code);
})
// START APP //
app.listen(config.port, function () {
console.log('running at port ' + config.port);
console.log(config);
});