forked from mozilla/gitribution
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.js
46 lines (38 loc) · 1.12 KB
/
web.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
var express = require("express");
var data = require("./lib/data");
var fetchData = require("./fetch_data");
var app = express();
app.get('/', function(req, res) {
res.send("You're probably looking for /api or for more info about this app see https://github.com/adamlofting/gitribution");
});
app.get('/api', function(req, res) {
var date = null;
var team = null;
if (req.query.date) {
date = new Date(req.query.date);
if ( Object.prototype.toString.call(date) === "[object Date]" ) {
if ( isNaN( date.getTime() ) ) {
date = null;// date is not valid
}
}
else {
date = null;
}
}
if (!date) {
res.end('Invalid parameter: "date". Please format as 2013-12-25.');
return;
}
team = req.query.team;
if (!team) {
res.end('Missing parameter: "team". E.g. webmaker, openbadges, opennews, appmaker, sciencelab.');
return;
}
data.getContributorCounts(date, team, function gotCounts (err, result) {
res.json(result);
});
});
var port = Number(process.env.PORT || 5000);
app.listen(port, function() {
console.log("Listening on " + port);
});