forked from BonsaiDen/JavaScript-Garden
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
Latest commit
33 lines (32 loc) · 1.13 KB
/
Copy pathserver.js
File metadata and controls
33 lines (32 loc) · 1.13 KB
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
// This server implements a post-receive hook handler for github that will build the site
varbuild=require('./build').build,
qs=require('querystring'),
port=9900,
repoURL="https://github.com/ciembor/JavaScript-Garden";
require('http').createServer(function(request,response){
varpayload='';
try{
if(request.method==='POST'){
request.setEncoding('utf8');
request.on('data',function(data){
payload+=data;
});
request.on('end',function(){
console.log(payload);
payload=JSON.parse(qs.parse(payload).payload);
if(payload.repository.url===repoURL){
build();
}else{
response.writeHead(400);// Bad Request
}
});
response.writeHead(200);// OK
}else{
response.writeHead(405);// Method Not Allowed
}
}catch(e){
console.error("Error: "+e);
response.writeHead(500);// Internal Server Error
}
response.end();
}).listen(port);