-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
41 lines (37 loc) · 1013 Bytes
/
server.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
var express = require('express');
var request = require('request');
var app = express();
var port = process.env.PORT || 2211;
var morgan = require('morgan');
app.use(morgan('dev'));
function countUsers(callback){
var url = 'https://discordapp.com/api/guilds/303217943234215948/widget.json';
var count = 0
request.get({
url: url,
json: true,
headers: {'User-Agent': 'request'}
}, (err, res, data) => {
if (err) {
console.log('Error:', err);
return(callback(null, err))
} else if (res.statusCode !== 200) {
console.log('Status:', res.statusCode);
return(callback(null, res.statusCode));
} else {
data.members.forEach(function(e){
count++
})
return(callback(count, false))
}
});
}
app.get('/api/discord', function(req, res) {
countUsers(function (data, err) {
if (err) return res.send(err.toString())
var result = new Object()
result["count"] = data;
res.json(result)
})
})
app.listen(port)