forked from botwillacceptanything/botwillacceptanything
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebserver.js
28 lines (25 loc) · 810 Bytes
/
webserver.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
var express = require('express');
var app = express();
var git = require('gift');
var sanitizeHtml = require('sanitize-html');
function sanitizeAllHtml(dirty) {
return sanitizeHtml(dirty, { allowedTags: [] });
}
module.exports = function (config, gh) {
var server = app.listen(3000);
app.get('/', function (req, res) {
var repo = git(__dirname)
repo.commits(function (err, commits) {
var commitLog = commits.map(function (commit) {
return '<li>' +
sanitizeAllHtml(commit.author.name + ' added ' + commit.id) +
"<br />" +
sanitizeAllHtml(commit.message).replace("\n", '<br />') +
'</li>';
});
var response = 'Last 10 commits:<ul>';
response += commitLog.join('') + '</ul>';
res.send(response);
});
});
}