X-Git-Url: https://git.kengrimes.com/?p=henge%2Fkiak.git;a=blobdiff_plain;f=main.js;h=845e54b7509f3fbc16c7e88e0c15dfb95ffe2c18;hp=4ada8bbc4ea3891bde3997c5beab6a45cba7636d;hb=d5073d238a4bf9fa96adabf6872a67e6b92fc832;hpb=10b1fcdf58cde8a6c6d5ebfa4bba76ef2adcf3dd diff --git a/main.js b/main.js index 4ada8bb..845e54b 100644 --- a/main.js +++ b/main.js @@ -25,8 +25,16 @@ 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') - console.log(request) const serveFile = (fPath) => { fs.readFile(fPath, { encoding: 'utf8' }, (err, data) => { if (err || data == undefined) { @@ -61,10 +69,12 @@ const router = { } /* TODO: Handle reconnecting host */ else if (routeName in router.routes) { + const route = router.routes[routeName] - console.log(request) + /* Client is INIT GET */ - if (request) { + if (request.headers['x-strapp-type'] !== 'o') { + console.log('client init GET') response.writeHead(200, { 'Content-Type': 'text/html' }) response.write(`${router.skelPage[0]}${router.clientJS}${router.skelPage[1]}`) response.end() @@ -72,7 +82,11 @@ 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('client offer/answer GET') + //route.socket.send(JSON.parse(body.join(''))) + route.socket.on('message', (hostResponse) => { + console.log(hostResponse) + }) } } @@ -111,6 +125,7 @@ const router = { * @summary Boot up the router. With TLS, we must wait for file reads to sync. */ if (!opts['no-tls']) { + console.log('tls') let filesRead = 0 let key = undefined let cert = undefined