X-Git-Url: https://git.kengrimes.com/?p=henge%2Fkiak.git;a=blobdiff_plain;f=router.js;h=2085e9b166e411f9e46e4adadde35c8fe8fa1aaa;hp=411c4886c3323ff3f28e9768ec3bbe79479905c8;hb=d17ac76d8256b00eb253138a554c7d3d51139b9e;hpb=5ae8bb9adc37111641414da912600ea97d834874 diff --git a/router.js b/router.js index 411c488..2085e9b 100644 --- a/router.js +++ b/router.js @@ -83,7 +83,7 @@ exports = { console.log(err) }) console.log(`HTTP${(conf.tls == undefined) ? '' : 'S'} ` + - `Server Started on port ${conf.port}${this.httpdRoot ? + `Server Started on port ${conf.port}${this.httpdRoot ? `, serving files from ${this.httpdRoot}`:''}`) }, @@ -127,7 +127,6 @@ exports = { let htArgv = request.url.slice(1).split('?') const routeName = htArgv[0].split('/')[0] let route = this.routes[routeName] - console.log(`route is ${route}`) /* If the route exists, check if we are a returning host or a new client */ if (route) { if (route.bind) { @@ -141,11 +140,9 @@ exports = { // that isn't just "give you a route if it's available" on visit /* else if (route.origin == (request.headers['x-forwarded-for'] || request.connection.remoteAddress)) - this.serveHost(response, route, htArgv) - else */ - else { + this.serveHost(response, route, htArgv) */ + else this.serveClient(request, response, route) - } } /* If it's a valid routename that doesn't exist, make this client a host */ else if (this.validRoutes.test(routeName)) { @@ -224,7 +221,7 @@ exports = { serveClient: function (request, response, route) { const type = request.headers['x-strapp-type'] const pubKey = request.headers['x-strapp-pubkey'] - dlog(`Client ${type || 'HT'} request routed to ${route.name}`) + dlog(`Client ${type || 'HT GET'} request routed to ${route.name}`) switch (type) { case null: case undefined: @@ -239,6 +236,8 @@ exports = { if (pubKey) { let data = request.headers['x-strapp-offer'] route.pendingResponses.addResponse(pubKey, response) + dlog(`${route.origin}=>\n${pubKey}\n${type}`) + dlog(JSON.parse(data)) route.socket.send(`${pubKey} ${type} ${data}`) } else { @@ -294,7 +293,7 @@ exports = { this.serveHost(response, route, argv) }, - /** @func + /** @Func * @summary Serve a route to an authorized http host * @desc services host application to the client, establishing a socket * @arg {http.ServerResponse} response - response object to use @@ -339,7 +338,7 @@ exports = { * @arg {Object} route - the route over */ hostMessage: function (message, route) { - const argv = message.split(' ') + let argv = message.split(' ') const command = argv[0][0] argv = argv.slice(1) dlog(`Received host message from ${route.name}: ${command}`)