-/* const routeConnection = (request,response) => {
- const htArgv = request.url.slice(1).split("?")
- let routeName = /[^\/]*/.match(htArgv[0])[0]
- if (routeName === '')
- routeName = opts['index']
- if (routeName.indexOf('.') != -1) {
- if (routeName in fileBuf) {
- response.writeHead(200, { 'Content-Type': fileBuf[routeName].mime })
- response.write(fileBuf[routeName].data)
+const router = {
+ skelPage: fs.readFileSync('./skel.html', { encoding: 'utf8' }).split('<!--STRAPP_SRC-->'),
+ clientJS: fs.readFileSync(opts['client-js']),
+ hostJS: fs.readFileSync(opts['host-js']),
+ routes: {},
+ httpsOpt: undefined,
+ 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')
+ const serveFile = (fPath) => {
+ fs.readFile(fPath, { encoding: 'utf8' }, (err, data) => {
+ if (err || data == undefined) {
+ response.writeHead(404)
+ response.end()
+ }
+ else {
+ response.writeHead(200, { 'Content-Type': mime.lookup(fPath) })
+ response.write(data)
+ response.end()
+ }
+ })