X-Git-Url: https://git.kengrimes.com/?p=henge%2Fkiak.git;a=blobdiff_plain;f=strappServer.js;h=5cced853a78cb8cfef6618a7df5e54c6249ee44f;hp=2f8d383e23b27353b1b6bba4a9eab9ef442d5527;hb=4e6773ca79a062ba35c0659e32951e11a3db9cf6;hpb=2cc3f63700e73340ac203f260a884b45fc1de892 diff --git a/strappServer.js b/strappServer.js index 2f8d383..5cced85 100644 --- a/strappServer.js +++ b/strappServer.js @@ -15,15 +15,17 @@ const dlog = (msg) => console.log(msg) class Server { constructor(...props) { Object.assign(this, new.target.defaults, ...props) + this.pendingResponses = new Array(this.responseCacheSize) this.init() + return this } init() { if (this.cacheDir) this.loadCache(this.cacheDir, '') - require('fs').readFile('./strapp.js', (err, data) => { + require('fs').readFile('./www/strapp.min.js', (err, data) => { if (err) - throw new Error (err) - this.cache['strapp.js'] = ['application/javascript',data] + throw new Error(err) + this.cache['strapp.min.js'] = ['application/javascript',data] }) this.startHttpd() } @@ -64,7 +66,7 @@ class Server { const htArgv = request.url.slice(1).split('?') dlog(`request for ${request.url} received`) if (request.method === 'GET' && htArgv[0] in this.cache) { - dlog(`found in cache`) + dlog(`found ${htArgv[0]} in cache`) response.writeHead(200, { 'Content-Type': this.cache[htArgv[0]][0] }) response.write(this.cache[htArgv[0]][1]) response.end() @@ -146,9 +148,17 @@ class Server { this.app.send(`${args[0]} ${request.method} ${pubKey} ${msgID} ${data}`) } else { - response.writeHead(200, { 'Content-Type': 'text/html' }) - response.write(Server.bootstrapp) - response.end() + require('fs').readFile('./bootstrapp.html', (err, data) => { + if (err) { + response.writeHead(500) + response.end() + } + else { + response.writeHead(200, { 'Content-Type': 'text/html' }) + response.write(data) + response.end() + } + }) } } } @@ -158,7 +168,7 @@ Server.defaults = { host: undefined, cache: {}, cacheDir: './www', - pendingResponses: new Array(20), + responseCacheSize: 40, msgID: 0, answers: {}, remoteAdminKey: undefined, @@ -167,17 +177,6 @@ Server.defaults = { httpd: undefined, wsd: undefined } -Server.bootstrapp = ` - - - bootstrapp - - - - - - -` //TODO: module.exports = Server