-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (40 loc) · 1.56 KB
/
index.js
File metadata and controls
49 lines (40 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict';
var BaseService = require('./service');
var inherits = require('util').inherits;
var fs = require('fs');
var pkg = require('../package');
var InsightUI = function(options) {
BaseService.call(this, options);
// we don't use the options object for routePrefix and apiPrefix, since the
// client must be rebuilt with the proper options. A future version of
// Bitcore should allow for a service "build" step to make this better.
this.apiPrefix = pkg.insightConfig.apiPrefix;
this.servicePrefix = pkg.insightConfig.servicePrefix;
this.routePrefix = pkg.insightConfig.routePrefix;
};
InsightUI.dependencies = ['insight-api', 'bitcore-service'];
inherits(InsightUI, BaseService);
InsightUI.prototype.start = function(callback) {
this.indexFile = this.filterIndexHTML(fs.readFileSync(__dirname + '/../public/index-template.html', {encoding: 'utf8'}));
setImmediate(callback);
};
InsightUI.prototype.getRoutePrefix = function() {
return this.routePrefix;
};
InsightUI.prototype.setupRoutes = function(app, express) {
var self = this;
app.use(express.static(__dirname + '/../public'));
// if not in found, fall back to indexFile (404 is handled client-side)
app.use(function(req, res, next) {
res.setHeader('Content-Type', 'text/html');
res.send(self.indexFile);
});
};
InsightUI.prototype.filterIndexHTML = function(data) {
var transformed = data;
if (this.routePrefix !== '') {
transformed = transformed.replace('<base href="/"', '<base href="/' + this.routePrefix + '/"');
}
return transformed;
};
module.exports = InsightUI;