X-Git-Url: https://www.kengrimes.com/gitweb/?p=henge%2Fkiak.git;a=blobdiff_plain;f=main.js;h=35cffef84fcc0969f8fd214ee7f137f565b88a12;hp=f123a413fd73593d94bbbce8705586395cac3c90;hb=b5c8f98ab42b8e7128441e4a456dfd4fc02f0e86;hpb=d33866cf8b1a188ad9ab23a934986bfd1b4726cb diff --git a/main.js b/main.js index f123a41..35cffef 100644 --- a/main.js +++ b/main.js @@ -25,15 +25,6 @@ const router = { httpd: undefined, wsProtocol: opts['no-tls'] ? 'ws' : 'wss', respond: (request,response) => { - let body = [] - request.on('error', function(err) { - console.error(`error is ${err}`); - }).on('data', function(chunk) { - console.log(`chunk is ${chunk}`) - body.push(chunk); - }).on('end', function() { - console.log(`body is ${body}`) - }) console.log('server handling request') const serveFile = (fPath) => { fs.readFile(fPath, { encoding: 'utf8' }, (err, data) => { @@ -82,9 +73,15 @@ const router = { // (this happens when a client connects to an active route with no currently-online host) } else { /* Client sent offer, waiting for answer */ - console.log(JSON.parse(request.headers['x-strapp-type'])) + console.log('Server: Sending client offer to host') + route.socket.send(request.headers['x-strapp-type']) route.socket.on('message', (hostResponse) => { + console.log('Server: Sending host answer to client') console.log(hostResponse) + response.writeHead(200, { 'Content-Type': 'application/json' }) + response.write(hostResponse) + response.end() + }) }