added bitcore-node dir with dependent js files
This commit is contained in:
parent
ab9e4de749
commit
12775d3170
@ -1,6 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "insight-ui",
|
"name": "insight-ui",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
"bitcoreNode": "bitcore-node",
|
||||||
|
"insightConfig": {
|
||||||
|
"apiPrefix": "api",
|
||||||
|
"routePrefix": ""
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "ionic-app-scripts clean",
|
"clean": "ionic-app-scripts clean",
|
||||||
"build": "ionic-app-scripts build",
|
"build": "ionic-app-scripts build",
|
||||||
@ -62,4 +67,4 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
},
|
},
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
68
bitcore-node/index.js
Normal file
68
bitcore-node/index.js
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var BaseService = require('./service');
|
||||||
|
var inherits = require('util').inherits;
|
||||||
|
var fs = require('fs');
|
||||||
|
var exec = require('child_process').exec;
|
||||||
|
var pkg = require('../app/package.json');
|
||||||
|
|
||||||
|
var InsightUI = function(options) {
|
||||||
|
console.log('options are', options);
|
||||||
|
BaseService.call(this, options);
|
||||||
|
this.apiPrefix = options.apiPrefix || 'api';
|
||||||
|
this.routePrefix = options.routePrefix || '';
|
||||||
|
};
|
||||||
|
|
||||||
|
InsightUI.dependencies = ['insight-api'];
|
||||||
|
|
||||||
|
inherits(InsightUI, BaseService);
|
||||||
|
|
||||||
|
InsightUI.prototype.start = function(callback) {
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
console.log('pkg before', pkg);
|
||||||
|
pkg.insightConfig.apiPrefix = self.apiPrefix;
|
||||||
|
pkg.insightConfig.routePrefix = self.routePrefix;
|
||||||
|
console.log('pkg after', pkg);
|
||||||
|
console.log('dirname', __dirname);
|
||||||
|
|
||||||
|
fs.writeFileSync(__dirname + '/../app/package.json', JSON.stringify(pkg, null, 2));
|
||||||
|
/*
|
||||||
|
exec('cd ' + __dirname + '/../;' +
|
||||||
|
' npm run install-and-build', function(err) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
self.indexFile = self.filterIndexHTML(fs.readFileSync(__dirname + '/../app/www/index.html', {encoding: 'utf8'}));
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
self.indexFile = self.filterIndexHTML(fs.readFileSync(__dirname + '/../app/www/index.html', {encoding: 'utf8'}));
|
||||||
|
callback();
|
||||||
|
};
|
||||||
|
|
||||||
|
InsightUI.prototype.getRoutePrefix = function() {
|
||||||
|
return this.routePrefix;
|
||||||
|
};
|
||||||
|
|
||||||
|
InsightUI.prototype.setupRoutes = function(app, express) {
|
||||||
|
var self = this;
|
||||||
|
app.use(express.static(__dirname + '/../app/www'));
|
||||||
|
// if not in found, fall back to indexFile (404 is handled client-side)
|
||||||
|
/*
|
||||||
|
app.use(function(req, res) {
|
||||||
|
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;
|
||||||
91
bitcore-node/service.js
Normal file
91
bitcore-node/service.js
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var util = require('util');
|
||||||
|
var EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
|
var Service = function(options) {
|
||||||
|
EventEmitter.call(this);
|
||||||
|
|
||||||
|
this.node = options.node;
|
||||||
|
this.name = options.name;
|
||||||
|
};
|
||||||
|
|
||||||
|
util.inherits(Service, EventEmitter);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes the dependencies that should be loaded before this service.
|
||||||
|
*/
|
||||||
|
Service.dependencies = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* blockHandler
|
||||||
|
* @param {Block} block - the block being added or removed from the chain
|
||||||
|
* @param {Boolean} add - whether the block is being added or removed
|
||||||
|
* @param {Function} callback - call with the leveldb database operations to perform
|
||||||
|
*/
|
||||||
|
Service.prototype.blockHandler = function(block, add, callback) {
|
||||||
|
// implement in the child class
|
||||||
|
setImmediate(function() {
|
||||||
|
callback(null, []);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the bus events available for subscription
|
||||||
|
* @return {Array} an array of event info
|
||||||
|
*/
|
||||||
|
Service.prototype.getPublishEvents = function() {
|
||||||
|
// Example:
|
||||||
|
// return [
|
||||||
|
// ['eventname', this, this.subscribeEvent, this.unsubscribeEvent],
|
||||||
|
// ];
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the API methods to expose
|
||||||
|
* @return {Array} return array of methods
|
||||||
|
*/
|
||||||
|
Service.prototype.getAPIMethods = function() {
|
||||||
|
// Example:
|
||||||
|
// return [
|
||||||
|
// ['getData', this, this.getData, 1]
|
||||||
|
// ];
|
||||||
|
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Example:
|
||||||
|
// Service.prototype.getData = function(arg1, callback) {
|
||||||
|
//
|
||||||
|
// };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function which is called when module is first initialized
|
||||||
|
*/
|
||||||
|
Service.prototype.start = function(done) {
|
||||||
|
setImmediate(done);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to be called when bitcore-node is stopped
|
||||||
|
*/
|
||||||
|
Service.prototype.stop = function(done) {
|
||||||
|
setImmediate(done);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup express routes
|
||||||
|
* @param {Express} app
|
||||||
|
*/
|
||||||
|
Service.prototype.setupRoutes = function(app) {
|
||||||
|
// Setup express routes here
|
||||||
|
};
|
||||||
|
|
||||||
|
Service.prototype.getRoutePrefix = function() {
|
||||||
|
return this.name;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = Service;
|
||||||
Loading…
Reference in New Issue
Block a user