skeletal structure for bootstrap.js
[henge/kiak.git] / router.js
index da32c95..2085e9b 100644 (file)
--- a/router.js
+++ b/router.js
@@ -83,11 +83,7 @@ exports = {
         console.log(err)
       })
     console.log(`HTTP${(conf.tls == undefined) ? '' : 'S'} ` +
-<<<<<<< HEAD
-                `Server Started on port ${conf.port}${this.httpdRoot ?
-=======
                 `Server Started on port ${conf.port}${this.httpdRoot ? 
->>>>>>> 3f5fce84645ec2c59aec0908807d1e9cb3e05e2d
                 `, serving files from ${this.httpdRoot}`:''}`)
   },
 
@@ -131,10 +127,6 @@ exports = {
     let htArgv = request.url.slice(1).split('?')
     const routeName = htArgv[0].split('/')[0]
     let route = this.routes[routeName]
-<<<<<<< HEAD
-    console.log(`route is ${route}`)
-=======
->>>>>>> 3f5fce84645ec2c59aec0908807d1e9cb3e05e2d
     /* If the route exists, check if we are a returning host or a new client */
     if (route) {
       if (route.bind) {
@@ -148,14 +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 */
-<<<<<<< HEAD
-      else {
-=======
->>>>>>> 3f5fce84645ec2c59aec0908807d1e9cb3e05e2d
+        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)) {
@@ -234,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:
@@ -249,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 {
@@ -262,11 +251,7 @@ exports = {
     }
   },
 
-<<<<<<< HEAD
   /** @func
-=======
-  /** @func    
->>>>>>> 3f5fce84645ec2c59aec0908807d1e9cb3e05e2d
    * @summary Create a new route for a host
    * @desc    makes a new route for the given route name
    * @arg     {string} routeName - name of the new route
@@ -301,22 +286,14 @@ exports = {
       })
     route.pendingResponses.addResponse = function (key, response_p) {
       let responses = this.get(key) || []
-<<<<<<< HEAD
       responses.push(response_p)
       this.set(key, responses)
-=======
-      this.set(key, responses.push(response_p))
->>>>>>> 3f5fce84645ec2c59aec0908807d1e9cb3e05e2d
     }
     this.routes[routeName] = route
     this.serveHost(response, route, argv)
   },
 
-<<<<<<< HEAD
-  /** @func
-=======
-  /** @func    
->>>>>>> 3f5fce84645ec2c59aec0908807d1e9cb3e05e2d
+  /** @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
@@ -361,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}`)