X-Git-Url: https://git.kengrimes.com/?p=henge%2Fkiak.git;a=blobdiff_plain;f=main.js;h=4ada8bbc4ea3891bde3997c5beab6a45cba7636d;hp=75e762f7f231c92a5431310c5d82890f8fd27a56;hb=10b1fcdf58cde8a6c6d5ebfa4bba76ef2adcf3dd;hpb=fee7676065c0016e999b2069b6a2b1a28d2b48d4 diff --git a/main.js b/main.js index 75e762f..4ada8bb 100644 --- a/main.js +++ b/main.js @@ -25,6 +25,8 @@ const router = { httpd: undefined, wsProtocol: opts['no-tls'] ? 'ws' : 'wss', respond: (request,response) => { + console.log('server handling request') + console.log(request) const serveFile = (fPath) => { fs.readFile(fPath, { encoding: 'utf8' }, (err, data) => { if (err || data == undefined) { @@ -42,7 +44,7 @@ const router = { let routePath = htArgv[0].split('/') let routeName = routePath[0] if (routeName === '' || routeName === 'index.html') - serveFile(opts['index']) + serveFile(opts['index']) else if (routeName in opts['bindings']) { let localPath = path.normalize(opts['bindings'][routeName].concat(path.sep + routePath.slice(1).join(path.sep))) if (localPath.includes(opts['bindings'][routeName])) { @@ -57,14 +59,22 @@ const router = { console.log(`SEC: ${localPath} references files not in route`) } } + /* TODO: Handle reconnecting host */ else if (routeName in router.routes) { const route = router.routes[routeName] - response.writeHead(200, { 'Content-Type': 'text/html' }) - response.write(`${router.skelPage[0]}${router.clientJS}${router.skelPage[1]}`) - response.end() - //TODO: if route.socket == undefined: have server delay this send until host connects - // (this happens when a client connects to an active route with no currently-online host) - route.socket.send(request.headers['x-forwarded-for'] || request.connection.remoteAddress) + console.log(request) + /* Client is INIT GET */ + if (request) { + response.writeHead(200, { 'Content-Type': 'text/html' }) + response.write(`${router.skelPage[0]}${router.clientJS}${router.skelPage[1]}`) + response.end() + //TODO: if route.socket == undefined: have server delay this send until host connects + // (this happens when a client connects to an active route with no currently-online host) + } + else { /* Client sent offer, waiting for answer */ + + } + } else { router.routes[routeName] = true