From 62e1225dd3d77a2dcad71710088d37c2056cd5a4 Mon Sep 17 00:00:00 2001 From: k Date: Mon, 3 Apr 2017 20:04:16 -0400 Subject: [PATCH] Fixed over-matching of index route. --- bitcore-node/index.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/bitcore-node/index.js b/bitcore-node/index.js index 32a3a17..5b1f1ba 100644 --- a/bitcore-node/index.js +++ b/bitcore-node/index.js @@ -23,8 +23,20 @@ InsightUI.dependencies = ['insight-api']; inherits(InsightUI, BaseService); InsightUI.prototype.start = function(callback) { - this.indexFile = this.filterIndexHTML(fs.readFileSync(__dirname + '/../public/index.html', {encoding: 'utf8'})); - setImmediate(callback); + + var self = this; + + var indexFile = __dirname + '/../public/index.html'; + + fs.readFile(indexFile, { encoding: 'utf8' }, function(err, data) { + + if(err) { + return callback(err); + } + + self.indexFile = self.filterIndexHTML(data); + callback(); + }); }; InsightUI.prototype.getRoutePrefix = function() { @@ -35,14 +47,13 @@ InsightUI.prototype.setupRoutes = function(app, express) { var self = this; app.use('/', function(req, res, next){ - if (req.headers.accept && req.headers.accept.indexOf('text/html') !== -1 && - req.headers["X-Requested-With"] !== 'XMLHttpRequest' - ) { - res.setHeader('Content-Type', 'text/html'); + + if (req.url === '/') { res.send(self.indexFile); } else { express.static(__dirname + '/../public')(req, res, next); } + }); };