router bootup successful, pending client/host revision
authorken <ken@kengrimes.com>
Mon, 10 Jul 2017 03:12:19 +0000 (03:12 +0000)
committerken <ken@kengrimes.com>
Mon, 10 Jul 2017 03:12:19 +0000 (03:12 +0000)
router.js
strapp.js

index d8e9a8b..35a2433 100644 (file)
--- a/router.js
+++ b/router.js
@@ -15,6 +15,11 @@ exports = {
    */
   validRoutes: /[a-zA-Z][a-zA-Z0-9\-_]*/,
 
+  /** A map of routes
+   * @prop {Object.Map} routes - all the routes!
+   */
+  routes: {},
+
   /** Parameters set on bootup (startHttpServer)
    * @prop {string[2]} skelPage - html document split in twain for JS injection
    * @prop {string} clientJS - jerverscripps to inject in skelPage for clients
@@ -59,13 +64,14 @@ exports = {
         })
         this.httpd =
           require('https').createServer(this.httpsOpts, this.httpdListener)
+          .listen(conf.port)
       })
-    this.httpd.listen(conf.port)
-    this.httpdRoot =
-      conf.httpdRoot ? require('path').normalize(conf.httpdRoot) : undefined
-    while (this.httpdRoot[this.httpdRoot.length - 1] == require('path').sep)
-      this.httpdRoot = this.httpdRoot.slice(0,-1)
-    this.syncReads(conf.skelFile, conf.clientJS, conf.hostJS)
+    if (conf.httpdRoot) {
+      this.httpdRoot = require('path').normalize(conf.httpdRoot)
+      while (this.httpdRoot[this.httpdRoot.length - 1] == require('path').sep)
+        this.httpdRoot = this.httpdRoot.slice(0,-1)
+    }
+    this.syncReads([conf.skelFile, conf.clientJS, conf.hostJS])
       .then((results) => {
         this.skelPage = results[conf.skelFile].split('<!--STRAPP_SRC-->')
         this.clientJS = results[conf.clientJS]
@@ -97,7 +103,7 @@ exports = {
         && this.bindJail != path)
       throw new Error(`${routeName}:${path} jailed to ${this.bindJail}`)
     if (require('fs').existsSync(path)) {
-      this.route[routeName] = {
+      this.routes[routeName] = {
         bind: {
           path: path,
           dir: require('fs').lstatSync(path).isDirectory()
@@ -396,7 +402,7 @@ exports = {
    * @arg     {Object} [readOpts] - options to pass to fs.readFile()
    */
   syncReads: (files, readOpts) => new Promise((resolve,reject) => {
-    dlog(`syncReads: ${files}`)
+    dlog(`syncing reads from ${files}`)
     let count = 0
     let results = {}
     const read_cb = (fileName) => (err, data) => {
@@ -412,5 +418,6 @@ exports = {
     files.forEach((file) =>
                   require('fs').readFile(file, readOpts, read_cb(file)))
   })
-  
 }
+
+module.exports = exports
index ebca88d..dc95479 100644 (file)
--- a/strapp.js
+++ b/strapp.js
@@ -11,7 +11,7 @@ const opts = require('./opts.js')
 const router = require('./router.js')
 
 Object.keys(opts['bindings']).forEach((key) => {
-  router.createBind(key, opts['bindings'].key)
+  router.createBind(key, opts['bindings'][key])
 })
 
 router.startHttpServer({