From 14b51852107983d03b98406ab644132712fabcd3 Mon Sep 17 00:00:00 2001 From: BigBlueHat Date: Mon, 8 May 2017 16:21:59 -0400 Subject: [PATCH 1/8] Ignore node_modules --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ From b6c5bd9a3111ead4c18b92a244389293018debf1 Mon Sep 17 00:00:00 2001 From: BigBlueHat Date: Mon, 8 May 2017 16:38:48 -0400 Subject: [PATCH 2/8] Ignore build.js and config.json Enforce local building of code--for now. Prevent accidently over sharing credentials. --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index c2658d7..96811e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ node_modules/ + +# project specifics +build.js +config.json From d935e55bdc58ed27bae405a306de3303bdadcbe4 Mon Sep 17 00:00:00 2001 From: BigBlueHat Date: Mon, 8 May 2017 16:40:36 -0400 Subject: [PATCH 3/8] Host out of www/ folder by default --- .gitignore | 1 + config.json.default | 11 +++++++---- index.js | 18 ++++++++++++------ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 96811e8..984af91 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules/ # project specifics build.js config.json +www/ diff --git a/config.json.default b/config.json.default index bfa1fdf..cd7ebec 100644 --- a/config.json.default +++ b/config.json.default @@ -3,11 +3,14 @@ "sslKey": "/path/to/privkey.pem", "sslCert": "/path/to/cert.pem", "proxyURL": "https://dokie.li/proxy?uri=", - "rootPath": ".", + "rootPath": "www/", "basePath": "", - "inboxPath": "inbox/", - "queuePath": "queue/", - "annotationPath": "annotation/", + + "annotationPath": "www/annotation/", + "inboxPath": "www/inbox/", + "queuePath": "www/queue/", + "reportsPath": "www/reports/", + "maxPayloadSize": 10000, "maxResourceCount": 10 } diff --git a/index.js b/index.js index c8025c0..0909f75 100644 --- a/index.js +++ b/index.js @@ -152,17 +152,23 @@ function config(configFile){ config['port'] = config.port || 3000; config['scheme'] = (config.sslKey && config.sslCert) ? 'https' : 'http'; config['authority'] = config.scheme + '://' + config.hostname + ':' + config.port; - config['rootPath'] = config.rootPath || ((process.cwd() != __dirname) ? process.cwd() : '.'); + config['rootPath'] = config.rootPath || ((process.cwd() != __dirname) ? process.cwd() : 'www/'); config['basePath'] = config.basePath || ''; - config['inboxPath'] = config.inboxPath || 'inbox/'; - config['queuePath'] = config.queuePath || 'queue/'; - config['annotationPath'] = config.annotationPath || 'annotation/'; - config['reportsPath'] = config.reportsPath || 'reports/'; + + // pre-provided resource endpoints + config['annotationPath'] = config.annotationPath || config['rootPath'] + 'annotation/'; + config['inboxPath'] = config.inboxPath || config['rootPath'] + 'inbox/'; + config['queuePath'] = config.queuePath || config['rootPath'] + 'queue/'; + config['reportsPath'] = config.reportsPath || config['rootPath'] + 'reports/'; + config['maxPayloadSize'] = config.maxPayloadSize || 100000; config['maxResourceCount'] = config.maxResourceCount || 100; config['proxyURL'] = config.proxyURL || 'https://dokie.li/proxy?uri='; - var createDirectories = [config['inboxPath'], config['queuePath'], config['annotationPath'], config['reportsPath']]; + var createDirectories = [ + config['rootPath'], config['annotationPath'], config['inboxPath'], + config['queuePath'], config['reportsPath'] + ]; createDirectories.forEach(function(path){ if(!fs.existsSync(path)){ fs.mkdirSync(path); } }); //console.log(config); From 738b3b4743a380bd7f86bc50e0fd0ad415921ad2 Mon Sep 17 00:00:00 2001 From: BigBlueHat Date: Wed, 10 May 2017 15:28:21 -0400 Subject: [PATCH 4/8] Copy index.html if absent in www/ This provides for bootstrapping a hosting directory with a minimal discovery HTML document. It is copied on the first run of the server, but not on subsequent runs to avoid overwriting changes. Re-bootstrapping simply requires moving the `index.html` from the `rootPath` directory. --- index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/index.js b/index.js index 0909f75..2674a3c 100644 --- a/index.js +++ b/index.js @@ -171,6 +171,14 @@ function config(configFile){ ]; createDirectories.forEach(function(path){ if(!fs.existsSync(path)){ fs.mkdirSync(path); } }); + // rootPath folder does not contain an index.html file...so we'll copy the + // default one in. + if (!fs.existsSync(config.rootPath + 'index.html') + && fs.existsSync(process.cwd() + '/index.html')) { + fs.createReadStream(process.cwd() + '/index.html') + .pipe(fs.createWriteStream(config.rootPath + 'index.html')); + } + //console.log(config); return config; } From a19a5c84508098d60d286052e47787c93b148fb2 Mon Sep 17 00:00:00 2001 From: BigBlueHat Date: Wed, 10 May 2017 16:12:02 -0400 Subject: [PATCH 5/8] Fix rootPath assumptions to work correctly rootPath is now...root. Other paths are all expected to be served from inside of rootPath (relatively). --- config.json.default | 8 ++++---- index.js | 27 +++++++++++++++++++-------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/config.json.default b/config.json.default index cd7ebec..0e1e51f 100644 --- a/config.json.default +++ b/config.json.default @@ -6,10 +6,10 @@ "rootPath": "www/", "basePath": "", - "annotationPath": "www/annotation/", - "inboxPath": "www/inbox/", - "queuePath": "www/queue/", - "reportsPath": "www/reports/", + "annotationPath": "annotation/", + "inboxPath": "inbox/", + "queuePath": "queue/", + "reportsPath": "reports/", "maxPayloadSize": 10000, "maxResourceCount": 10 diff --git a/index.js b/index.js index 2674a3c..aef6137 100644 --- a/index.js +++ b/index.js @@ -156,20 +156,31 @@ function config(configFile){ config['basePath'] = config.basePath || ''; // pre-provided resource endpoints - config['annotationPath'] = config.annotationPath || config['rootPath'] + 'annotation/'; - config['inboxPath'] = config.inboxPath || config['rootPath'] + 'inbox/'; - config['queuePath'] = config.queuePath || config['rootPath'] + 'queue/'; - config['reportsPath'] = config.reportsPath || config['rootPath'] + 'reports/'; + config['annotationPath'] = config.annotationPath || 'annotation/'; + config['inboxPath'] = config.inboxPath || 'inbox/'; + config['queuePath'] = config.queuePath || 'queue/'; + config['reportsPath'] = config.reportsPath || 'reports/'; config['maxPayloadSize'] = config.maxPayloadSize || 100000; config['maxResourceCount'] = config.maxResourceCount || 100; config['proxyURL'] = config.proxyURL || 'https://dokie.li/proxy?uri='; - var createDirectories = [ - config['rootPath'], config['annotationPath'], config['inboxPath'], - config['queuePath'], config['reportsPath'] + function createDir(path) { + if (!fs.existsSync(path)) { + fs.mkdirSync(path); + } + } + + // create the `rootPath` directory + createDir(config['rootPath']); + // ...all others are relative to `rootPath` + var createThese = [ + config['annotationPath'], config['inboxPath'], config['queuePath'], + config['reportsPath'] ]; - createDirectories.forEach(function(path){ if(!fs.existsSync(path)){ fs.mkdirSync(path); } }); + createThese.forEach(function(path) { + createDir(config['rootPath'] + path); + }); // rootPath folder does not contain an index.html file...so we'll copy the // default one in. From 9582f97638c28df783681271e343e3db4628232c Mon Sep 17 00:00:00 2001 From: BigBlueHat Date: Wed, 10 May 2017 16:21:16 -0400 Subject: [PATCH 6/8] Fix requestedPath construction Avoids double // issues --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index aef6137..b800803 100644 --- a/index.js +++ b/index.js @@ -276,7 +276,8 @@ console.log(config); app.use(function(req, res, next) { // module.exports.accept = accept = accepts(req); req.requestedType = req.accepts(availableTypes); - req.requestedPath = config.rootPath + req.originalUrl; + // remove initial `/` from `originalUrl since `rootPath` has one + req.requestedPath = config.rootPath + req.originalUrl.substr(1); // console.log(req); // console.log(res); From e94df7d5faca858bd27ab8e079cf19b24d24c1e9 Mon Sep 17 00:00:00 2001 From: BigBlueHat Date: Thu, 11 May 2017 09:19:12 -0400 Subject: [PATCH 7/8] Make www/ the default when no config.json --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index b800803..661a9ff 100644 --- a/index.js +++ b/index.js @@ -152,7 +152,7 @@ function config(configFile){ config['port'] = config.port || 3000; config['scheme'] = (config.sslKey && config.sslCert) ? 'https' : 'http'; config['authority'] = config.scheme + '://' + config.hostname + ':' + config.port; - config['rootPath'] = config.rootPath || ((process.cwd() != __dirname) ? process.cwd() : 'www/'); + config['rootPath'] = config.rootPath || ((process.cwd() != __dirname) ? process.cwd() + '/www/' : 'www/'); config['basePath'] = config.basePath || ''; // pre-provided resource endpoints From 7077aa1005c5368a062785afd08d8f19ca5203de Mon Sep 17 00:00:00 2001 From: BigBlueHat Date: Thu, 11 May 2017 09:21:22 -0400 Subject: [PATCH 8/8] Move createDir out of config() for wider use --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 661a9ff..0b01dd9 100644 --- a/index.js +++ b/index.js @@ -144,6 +144,12 @@ function getConfigFile(configFile){ return config; } +function createDir(path) { + if (!fs.existsSync(path)) { + fs.mkdirSync(path); + } +} + function config(configFile){ var config = getConfigFile(configFile); @@ -165,12 +171,6 @@ function config(configFile){ config['maxResourceCount'] = config.maxResourceCount || 100; config['proxyURL'] = config.proxyURL || 'https://dokie.li/proxy?uri='; - function createDir(path) { - if (!fs.existsSync(path)) { - fs.mkdirSync(path); - } - } - // create the `rootPath` directory createDir(config['rootPath']); // ...all others are relative to `rootPath`