Skip to content

Commit 7155ff0

Browse files
author
Chris Kleeschulte
committed
Added a build runner in line with starting the service.
1 parent e94154b commit 7155ff0

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

bitcore-node/index.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,35 @@
33
var BaseService = require('./service');
44
var inherits = require('util').inherits;
55
var fs = require('fs');
6-
var pkg = require('../package');
6+
var exec = require('child_process').exec;
7+
var pkg = require('../package.json');
78

89
var InsightUI = function(options) {
910
BaseService.call(this, options);
10-
// we don't use the options object for routePrefix and apiPrefix, since the
11-
// client must be rebuilt with the proper options. A future version of
12-
// Bitcore should allow for a service "build" step to make this better.
13-
this.apiPrefix = pkg.insightConfig.apiPrefix;
14-
this.routePrefix = pkg.insightConfig.routePrefix;
11+
this.apiPrefix = options.apiPrefix || 'api';
12+
this.routePrefix = options.routePrefix || '';
1513
};
1614

1715
InsightUI.dependencies = ['insight-api'];
1816

1917
inherits(InsightUI, BaseService);
2018

2119
InsightUI.prototype.start = function(callback) {
22-
this.indexFile = this.filterIndexHTML(fs.readFileSync(__dirname + '/../public/index-template.html', {encoding: 'utf8'}));
23-
setImmediate(callback);
20+
21+
var self = this;
22+
pkg.insightConfig.apiPrefix = self.apiPrefix;
23+
pkg.insightConfig.routePrefix = self.routePrefix;
24+
25+
fs.writeFileSync(__dirname + '/../package.json', JSON.stringify(pkg, null, 2));
26+
exec('pushd ' + __dirname + '/../;' +
27+
' npm run install-and-build; popd', function(err) {
28+
if (err) {
29+
return callback(err);
30+
}
31+
self.indexFile = self.filterIndexHTML(fs.readFileSync(__dirname + '/../public/index-template.html', {encoding: 'utf8'}));
32+
callback();
33+
});
34+
2435
};
2536

2637
InsightUI.prototype.getRoutePrefix = function() {
@@ -31,7 +42,7 @@ InsightUI.prototype.setupRoutes = function(app, express) {
3142
var self = this;
3243
app.use(express.static(__dirname + '/../public'));
3344
// if not in found, fall back to indexFile (404 is handled client-side)
34-
app.use(function(req, res, next) {
45+
app.use(function(req, res) {
3546
res.setHeader('Content-Type', 'text/html');
3647
res.send(self.indexFile);
3748
});

package-lock.json

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "insight-ui",
33
"description": "An open-source frontend for the Insight API. The Insight API provides you with a convenient, powerful and simple way to query and broadcast data on the bitcoin network and build your own services with it.",
4-
"version": "5.0.0-beta.1",
4+
"version": "5.0.0-beta.12",
55
"repository": "git://github.com/bitpay/insight-ui.git",
66
"bugs": {
77
"url": "https://github.com/bitpay/insight-ui/issues"
@@ -18,12 +18,13 @@
1818
],
1919
"bitcoreNode": "bitcore-node",
2020
"insightConfig": {
21-
"apiPrefix": "insight-api",
22-
"routePrefix": "insight"
21+
"apiPrefix": "api",
22+
"routePrefix": ""
2323
},
2424
"scripts": {
2525
"build": "bower install && grunt compile",
26-
"watch": "grunt"
26+
"watch": "grunt",
27+
"install-and-build": "npm install && npm run build"
2728
},
2829
"dependencies": {},
2930
"devDependencies": {

0 commit comments

Comments
 (0)