- if (readOpts == undefined)
- readOpts = { encoding: 'utf8' }
- files.forEach((file) => fs.readFile(file, readOpts, read_cb(file)))
- }),
-
- /** @func
- * @summary Main router listener
- * @desc listens for http client requests and services routes/files
- * @arg {http.ClientRequest} request
- * @arg {http.ServerResponse} response
+ this.syncReads([conf.skelFile, conf.clientJS, conf.hostJS])
+ .then((results) => {
+ this.skelPage = results[conf.skelFile].split('<!--STRAPP_SRC-->')
+ this.clientJS = results[conf.clientJS]
+ this.hostJS = results[conf.hostJS]
+ })
+ .catch((err) => {
+ console.log(err)
+ })
+ console.log(`HTTP${(conf.tls == undefined) ? '' : 'S'} ` +
+ `Server Started on port ${conf.port}${this.httpdRoot ?
+ `, serving files from ${this.httpdRoot}`:''}`)
+ },
+
+ /** @func
+ * @summary Create a binding for the server
+ * @desc makes a new route which is bound to a file or a path. routes
+ * bound to files always serve that file, regardless of any
+ * additional path parameters provided by the URI
+ * @arg {string} routeName - the route to create
+ * @arg {string} path - the path to the file or directory to bind
+ */
+ createBind: function (routeName, path) {
+ dlog(`Binding ${routeName} to ${path}`)
+ if (routeName in this.routes)
+ throw new Error(`route ${routeName} already exists`)
+ path = require('path').normalize(path)
+ if (this.bindJail
+ && path.indexOf(`${this.bindJail}/`) !== 0
+ && this.bindJail != path)
+ throw new Error(`${routeName}:${path} jailed to ${this.bindJail}`)
+ if (require('fs').existsSync(path)) {
+ this.routes[routeName] = {
+ bind: {
+ path: path,
+ dir: require('fs').lstatSync(path).isDirectory()
+ }
+ }
+ }
+ else
+ throw new Error(`${path} not found, ${routeName} not bound`)
+ },
+
+ /** @func
+ * @summary Router
+ * @desc listens for http client requests and services routes/files
+ * @arg {http.ClientRequest} request
+ * @arg {http.ServerResponse} response