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) {
}
/* 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()
// (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)
+ })
}
}
* @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