Skip to content

Commit

Permalink
Added a build runner in line with starting the service.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Kleeschulte committed Sep 26, 2017
1 parent e94154b commit 7155ff0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 30 deletions.
29 changes: 20 additions & 9 deletions bitcore-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,35 @@
var BaseService = require('./service');
var inherits = require('util').inherits;
var fs = require('fs');
var pkg = require('../package');
var exec = require('child_process').exec;
var pkg = require('../package.json');

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.routePrefix = pkg.insightConfig.routePrefix;
this.apiPrefix = options.apiPrefix || 'api';
this.routePrefix = options.routePrefix || '';
};

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

inherits(InsightUI, BaseService);

InsightUI.prototype.start = function(callback) {
this.indexFile = this.filterIndexHTML(fs.readFileSync(__dirname + '/../public/index-template.html', {encoding: 'utf8'}));
setImmediate(callback);

var self = this;
pkg.insightConfig.apiPrefix = self.apiPrefix;
pkg.insightConfig.routePrefix = self.routePrefix;

fs.writeFileSync(__dirname + '/../package.json', JSON.stringify(pkg, null, 2));
exec('pushd ' + __dirname + '/../;' +
' npm run install-and-build; popd', function(err) {
if (err) {
return callback(err);
}
self.indexFile = self.filterIndexHTML(fs.readFileSync(__dirname + '/../public/index-template.html', {encoding: 'utf8'}));
callback();
});

};

InsightUI.prototype.getRoutePrefix = function() {
Expand All @@ -31,7 +42,7 @@ 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) {
app.use(function(req, res) {
res.setHeader('Content-Type', 'text/html');
res.send(self.indexFile);
});
Expand Down
34 changes: 17 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "insight-ui",
"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.",
"version": "5.0.0-beta.1",
"version": "5.0.0-beta.12",
"repository": "git://github.com/bitpay/insight-ui.git",
"bugs": {
"url": "https://github.com/bitpay/insight-ui/issues"
Expand All @@ -18,12 +18,13 @@
],
"bitcoreNode": "bitcore-node",
"insightConfig": {
"apiPrefix": "insight-api",
"routePrefix": "insight"
"apiPrefix": "api",
"routePrefix": ""
},
"scripts": {
"build": "bower install && grunt compile",
"watch": "grunt"
"watch": "grunt",
"install-and-build": "npm install && npm run build"
},
"dependencies": {},
"devDependencies": {
Expand Down

0 comments on commit 7155ff0

Please sign in to comment.