httpdRoot: undefined,
bindJail: undefined,
- /** @func
+ /** @func
* @summary Start main HTTP server
* @desc starts up an HTTP or HTTPS server used for routing
* @arg {Object} conf - object containing configuration properties
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}`:''}`)
},
throw new Error(`${path} not found, ${routeName} not bound`)
},
- /** @func
+ /** @func
* @summary Router
* @desc listens for http client requests and services routes/files
* @arg {http.ClientRequest} request
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) {
this.serveBind(response, route.bind, htArgv)
}
//TODO: auth better than this (ip spoofing is easy)
- else if (route.origin == (request.headers['x-forwarded-for'] ||
+ // but this will require a more involved host-creation process
+ // 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 */
+<<<<<<< HEAD
+ else {
+=======
+>>>>>>> 3f5fce84645ec2c59aec0908807d1e9cb3e05e2d
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)) {
this.serveFile(response, bind.path)
},
- /** @func
+ /** @func
* @summary Serve a route to an http client
* @desc routes may be bound to the filesystem, or to an outgoing host
* @arg {http.ClientRequest} request - request from the client
case 'client-sdp-offer':
let data = ''
if (pubKey) {
+ let data = request.headers['x-strapp-offer']
route.pendingResponses.addResponse(pubKey, response)
- request.on('data', (chunk) => data += chunk)
- request.on('end', () => route.socket.send(`${pubKey} ${type} ${data}`))
+ route.socket.send(`${pubKey} ${type} ${data}`)
}
else {
response.writeHead(401)
}
},
+<<<<<<< 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
socket: undefined
}
route.httpd.listen(port)
- route.wsd = new (require('ws').Server)({
- server: httpd
- //verifyClient: (info) =>
- //info.origin == origin && (info.secure || !this.httpsOpts)
- })
- route.wsd.on('connection', (socket) => {
- route.socket = socket
- socket.on('message', (msg) =>
- this.hostMessage(msg,route))
- })
+ route.wsd = new (require('ws').Server)({ server: httpd })
+ .on('connection', (socket) => {
+ route.socket = socket
+ socket.on('message', (msg) =>
+ this.hostMessage(msg,route))
+ })
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
* @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
}
},
- /** @func
+ /** @func
* @summary Serve a file to an http client after a request
* @desc reads files from the system to be distributed to clients, and
* buffers recently accessed files
response.end()
})
},
-
- /** @func
+
+ /** @func
* @summary Synchronize Reading Multiple Files
* @desc reads an array of files into an object, whose keys are the
* input filenames, and values are the data read