-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (34 loc) · 1017 Bytes
/
server.js
File metadata and controls
43 lines (34 loc) · 1017 Bytes
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
//Lets require/import the HTTP module
var http = require('http');
//Lets define a port we want to listen to
const PORT=8080;
//We need a function which handles requests and send response
function handleRequest(request, response){
response.end('Building: ' + request.url);
}
//Create a server
var server = http.createServer(handleRequest);
//Lets start our server
server.listen(PORT, function(){
//Callback triggered when server is successfully listening. Hurray!
console.log("Server listening on: http://localhost:%s", PORT);
});
var exec = require('child_process').exec;
var cmd = 'YOUR docker command';
function handleRequest(request, response)
{
console.log("Request received");
var child = exec(cmd, {maxBuffer: 1024 * 5000}, function(error, stdout, stderr)
{
if( error )
console.log(error)
});
// Stream results
child.stdout.pipe( response );
child.stderr.pipe( process.stderr );
child.on('exit', function()
{
console.log('built');
return true;
});
}