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()
}
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()
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()
+ }
+ })
}
}
}
host: undefined,
cache: {},
cacheDir: './www',
- pendingResponses: new Array(20),
+ responseCacheSize: 40,
msgID: 0,
answers: {},
remoteAdminKey: undefined,
httpd: undefined,
wsd: undefined
}
-Server.bootstrapp = `
-<!DOCTYPE html>
-<html>
- <title>bootstrapp</title>
- <head>
- <script src='/strapp.js'></script>
- </head>
- <body>
- </body>
-</html>
-`
//TODO: module.exports = Server