Skip to content

Commit 85e1c76

Browse files
committed
add hook server
1 parent 9d2a559 commit 85e1c76

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

build.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,5 +197,9 @@ var Garden = Class(function(options) {
197197
}
198198
});
199199

200-
new Garden({dir: 'doc', template: 'garden.jade', out: 'site'});
200+
exports.build = function (options) {
201+
options = options || {dir: 'doc', template: 'garden.jade', out: 'site'};
202+
new Garden(options);
203+
}
201204

205+
exports.build();

server.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// This server implements a post-receive hook handler for github that will build the site
2+
var build = require('./build').build,
3+
qs = require('querystring'),
4+
port = 9900,
5+
repoURL = "https://github.com/cramerdev/JavaScript-Garden";
6+
7+
require('http').createServer(function (request, response) {
8+
var payload = '';
9+
try {
10+
if (request.method === 'POST') {
11+
request.setEncoding('utf8');
12+
request.on('data', function (data) {
13+
payload += data;
14+
});
15+
request.on('end', function () {
16+
console.log(payload);
17+
payload = JSON.parse(qs.parse(payload).payload);
18+
if (payload.repository.url === repoURL) {
19+
build();
20+
} else {
21+
response.writeHead(400); // Bad Request
22+
}
23+
});
24+
response.writeHead(200); // OK
25+
} else {
26+
response.writeHead(405); // Method Not Allowed
27+
}
28+
} catch (e) {
29+
console.error("Error: " + e);
30+
response.writeHead(500); // Internal Server Error
31+
}
32+
response.end();
33+
}).listen(port);

0 commit comments

Comments
 (0)