Skip to content

Commit 1d70f01

Browse files
author
Patrick Nagurny
committed
add bitcore-node service and make everything relative paths
1 parent 4253de1 commit 1d70f01

22 files changed

+217
-80
lines changed

bitcore-node/index.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
var BaseService = require('./service');
4+
var inherits = require('util').inherits;
5+
var fs = require('fs');
6+
7+
var InsightUI = function(options) {
8+
BaseService.call(this, options);
9+
};
10+
11+
InsightUI.dependencies = ['insight-api'];
12+
13+
inherits(InsightUI, BaseService);
14+
15+
InsightUI.prototype.start = function(callback) {
16+
this.indexFile = this.filterIndexHTML(fs.readFileSync(__dirname + '/../public/index.html', {encoding: 'utf8'}));
17+
setImmediate(callback);
18+
};
19+
20+
InsightUI.prototype.setupRoutes = function(app, express) {
21+
var self = this;
22+
23+
app.use('/', function(req, res, next){
24+
if (req.headers.accept && req.headers.accept.indexOf('text/html') !== -1 &&
25+
req.headers["X-Requested-With"] !== 'XMLHttpRequest'
26+
) {
27+
res.setHeader('Content-Type', 'text/html');
28+
res.send(self.indexFile);
29+
} else {
30+
express.static(__dirname + '/../public')(req, res, next);
31+
}
32+
});
33+
};
34+
35+
InsightUI.prototype.filterIndexHTML = function(data) {
36+
var transformed = data
37+
.replace(/<base href=\"\/\"/, '<base href="/insight/"')
38+
.replace(/apiPrefix = '\/api'/, "apiPrefix = '/insight-api'");
39+
return transformed;
40+
};
41+
42+
module.exports = InsightUI;

bitcore-node/service.js

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
'use strict';
2+
3+
var util = require('util');
4+
var EventEmitter = require('events').EventEmitter;
5+
6+
var Service = function(options) {
7+
EventEmitter.call(this);
8+
9+
this.node = options.node;
10+
this.name = options.name;
11+
};
12+
13+
util.inherits(Service, EventEmitter);
14+
15+
/**
16+
* Describes the dependencies that should be loaded before this service.
17+
*/
18+
Service.dependencies = [];
19+
20+
/**
21+
* blockHandler
22+
* @param {Block} block - the block being added or removed from the chain
23+
* @param {Boolean} add - whether the block is being added or removed
24+
* @param {Function} callback - call with the leveldb database operations to perform
25+
*/
26+
Service.prototype.blockHandler = function(block, add, callback) {
27+
// implement in the child class
28+
setImmediate(function() {
29+
callback(null, []);
30+
});
31+
};
32+
33+
/**
34+
* the bus events available for subscription
35+
* @return {Array} an array of event info
36+
*/
37+
Service.prototype.getPublishEvents = function() {
38+
// Example:
39+
// return [
40+
// ['eventname', this, this.subscribeEvent, this.unsubscribeEvent],
41+
// ];
42+
return [];
43+
};
44+
45+
/**
46+
* the API methods to expose
47+
* @return {Array} return array of methods
48+
*/
49+
Service.prototype.getAPIMethods = function() {
50+
// Example:
51+
// return [
52+
// ['getData', this, this.getData, 1]
53+
// ];
54+
55+
return [];
56+
};
57+
58+
// Example:
59+
// Service.prototype.getData = function(arg1, callback) {
60+
//
61+
// };
62+
63+
/**
64+
* Function which is called when module is first initialized
65+
*/
66+
Service.prototype.start = function(done) {
67+
setImmediate(done);
68+
};
69+
70+
/**
71+
* Function to be called when bitcore-node is stopped
72+
*/
73+
Service.prototype.stop = function(done) {
74+
setImmediate(done);
75+
};
76+
77+
/**
78+
* Setup express routes
79+
* @param {Express} app
80+
*/
81+
Service.prototype.setupRoutes = function(app) {
82+
// Setup express routes here
83+
};
84+
85+
Service.prototype.getRoutePrefix = function() {
86+
return this.name;
87+
};
88+
89+
90+
91+
module.exports = Service;

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"scripts": {
4242
"start": "INSIGHT_PUBLIC_PATH=public node node_modules/.bin/insight-bitcore-api"
4343
},
44+
"bitcoreNode": "bitcore-node",
4445
"dependencies": {
4546
"insight-bitcore-api": ">=0.2.14"
4647
},

public/index.html

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<!doctype html>
22
<html lang="en" data-ng-app="insight" data-ng-csp>
33
<head>
4+
<base href="/" />
45
<meta charset="UTF-8">
56
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
67
<meta name="viewport" content="width=device-width,initial-scale=1.0">
78
<meta name="fragment" content="!">
89
<title data-ng-bind="$root.title + $root.titleDetail + ' | Insight'">Insight</title>
910
<meta name="keywords" content="bitcoins, transactions, blocks, address, block chain, best block, mining difficulty, hash serialized">
1011
<meta name="description" content="Bitcoin Insight. View detailed information on all bitcoin transactions and block. {{ $root.title + $root.titleDetail }}">
11-
<link rel="shortcut icon" href="/img/icons/favicon.ico" type="image/x-icon">
12+
<link rel="shortcut icon" href="img/icons/favicon.ico" type="image/x-icon">
1213
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700,400italic">
13-
<link rel="stylesheet" href="/css/main.min.css">
14+
<link rel="stylesheet" href="css/main.min.css">
1415
</head>
1516
<body ng-cloak class="ng-cloak">
1617
<div>
@@ -39,7 +40,7 @@ <h3 class="modal-title">Scan Code</h3>
3940
</script>
4041
</div>
4142
<div id="wrap">
42-
<div class="navbar navbar-default navbar-fixed-top" data-ng-include="'/views/includes/header.html'" role='navigation'></div>
43+
<div class="navbar navbar-default navbar-fixed-top" data-ng-include="'views/includes/header.html'" role='navigation'></div>
4344
<section class="container" data-ng-view></section>
4445
</div>
4546
<div id="footer" role="navigation">
@@ -59,15 +60,16 @@ <h3 class="modal-title">Scan Code</h3>
5960
[
6061
<a href="/messages/verify" translate>verify message</a>
6162
<span> &middot; </span>
62-
<a href="/tx/send" translate>broadcast transaction</a>
63+
<a href="tx/send" translate>broadcast transaction</a>
6364
]
6465
</div>
6566
<a class="insight m10v pull-right" target="_blank" href="http://insight.is">insight <small>API v{{version}}</small></a>
6667
</div>
6768
</div>
69+
<script language="javascript">window.apiPrefix = '/api';</script>
6870
<script src="/socket.io/socket.io.js"></script>
69-
<script src="/js/vendors.min.js"></script>
70-
<script src="/js/angularjs-all.min.js"></script>
71-
<script src="/js/main.min.js"></script>
71+
<script src="js/vendors.min.js"></script>
72+
<script src="js/angularjs-all.min.js"></script>
73+
<script src="js/main.min.js"></script>
7274
</body>
7375
</html>

public/src/js/config.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,47 @@
44
angular.module('insight').config(function($routeProvider) {
55
$routeProvider.
66
when('/block/:blockHash', {
7-
templateUrl: '/views/block.html',
7+
templateUrl: 'views/block.html',
88
title: 'Bitcoin Block '
99
}).
1010
when('/block-index/:blockHeight', {
1111
controller: 'BlocksController',
12-
templateUrl: '/views/redirect.html'
12+
templateUrl: 'views/redirect.html'
1313
}).
1414
when('/tx/send', {
15-
templateUrl: '/views/transaction_sendraw.html',
15+
templateUrl: 'views/transaction_sendraw.html',
1616
title: 'Broadcast Raw Transaction'
1717
}).
1818
when('/tx/:txId/:v_type?/:v_index?', {
19-
templateUrl: '/views/transaction.html',
19+
templateUrl: 'views/transaction.html',
2020
title: 'Bitcoin Transaction '
2121
}).
2222
when('/', {
23-
templateUrl: '/views/index.html',
23+
templateUrl: 'views/index.html',
2424
title: 'Home'
2525
}).
2626
when('/blocks', {
27-
templateUrl: '/views/block_list.html',
27+
templateUrl: 'views/block_list.html',
2828
title: 'Bitcoin Blocks solved Today'
2929
}).
3030
when('/blocks-date/:blockDate/:startTimestamp?', {
31-
templateUrl: '/views/block_list.html',
31+
templateUrl: 'views/block_list.html',
3232
title: 'Bitcoin Blocks solved '
3333
}).
3434
when('/address/:addrStr', {
35-
templateUrl: '/views/address.html',
35+
templateUrl: 'views/address.html',
3636
title: 'Bitcoin Address '
3737
}).
3838
when('/status', {
39-
templateUrl: '/views/status.html',
39+
templateUrl: 'views/status.html',
4040
title: 'Status'
4141
}).
4242
when('/messages/verify', {
43-
templateUrl: '/views/messages_verify.html',
43+
templateUrl: 'views/messages_verify.html',
4444
title: 'Verify Message'
4545
})
4646
.otherwise({
47-
templateUrl: '/views/404.html',
47+
templateUrl: 'views/404.html',
4848
title: 'Error'
4949
});
5050
});

public/src/js/controllers/transactions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ angular.module('insight.transactions').controller('SendRawTransactionController'
189189
rawtx: $scope.transaction
190190
};
191191
$scope.status = 'loading';
192-
$http.post('/api/tx/send', postData)
192+
$http.post(window.apiPrefix + '/tx/send', postData)
193193
.success(function(data, status, headers, config) {
194194
if(typeof(data.txid) != 'string') {
195195
// API returned 200 but the format is not known

public/src/js/services/address.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
angular.module('insight.address').factory('Address',
44
function($resource) {
5-
return $resource('/api/addr/:addrStr/?noTxList=1', {
5+
return $resource(window.apiPrefix + '/addr/:addrStr/?noTxList=1', {
66
addrStr: '@addStr'
77
}, {
88
get: {
@@ -21,3 +21,4 @@ angular.module('insight.address').factory('Address',
2121
});
2222
});
2323

24+

public/src/js/services/blocks.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
angular.module('insight.blocks')
44
.factory('Block',
55
function($resource) {
6-
return $resource('/api/block/:blockHash', {
6+
return $resource(window.apiPrefix + '/block/:blockHash', {
77
blockHash: '@blockHash'
88
}, {
99
get: {
@@ -23,9 +23,9 @@ angular.module('insight.blocks')
2323
})
2424
.factory('Blocks',
2525
function($resource) {
26-
return $resource('/api/blocks');
26+
return $resource(window.apiPrefix + '/blocks');
2727
})
2828
.factory('BlockByHeight',
2929
function($resource) {
30-
return $resource('/api/block-index/:blockHeight');
30+
return $resource(window.apiPrefix + '/block-index/:blockHeight');
3131
});

public/src/js/services/currency.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
angular.module('insight.currency').factory('Currency',
44
function($resource) {
5-
return $resource('/api/currency');
5+
return $resource(window.apiPrefix + '/currency');
66
});

public/src/js/services/global.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ angular.module('insight.system')
88
])
99
.factory('Version',
1010
function($resource) {
11-
return $resource('/api/version');
11+
return $resource(window.apiPrefix + '/version');
1212
});

public/src/js/services/status.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
angular.module('insight.status')
44
.factory('Status',
55
function($resource) {
6-
return $resource('/api/status', {
6+
return $resource(window.apiPrefix + '/status', {
77
q: '@q'
88
});
99
})
1010
.factory('Sync',
1111
function($resource) {
12-
return $resource('/api/sync');
12+
return $resource(window.apiPrefix + '/sync');
1313
})
1414
.factory('PeerSync',
1515
function($resource) {
16-
return $resource('/api/peer');
16+
return $resource(window.apiPrefix + '/peer');
1717
});

public/src/js/services/transactions.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
angular.module('insight.transactions')
44
.factory('Transaction',
55
function($resource) {
6-
return $resource('/api/tx/:txId', {
6+
return $resource(window.apiPrefix + '/tx/:txId', {
77
txId: '@txId'
88
}, {
99
get: {
@@ -23,17 +23,17 @@ angular.module('insight.transactions')
2323
})
2424
.factory('TransactionsByBlock',
2525
function($resource) {
26-
return $resource('/api/txs', {
26+
return $resource(window.apiPrefix + '/txs', {
2727
block: '@block'
2828
});
2929
})
3030
.factory('TransactionsByAddress',
3131
function($resource) {
32-
return $resource('/api/txs', {
32+
return $resource(window.apiPrefix + '/txs', {
3333
address: '@address'
3434
});
3535
})
3636
.factory('Transactions',
3737
function($resource) {
38-
return $resource('/api/txs');
38+
return $resource(window.apiPrefix + '/txs');
3939
});

public/views/404.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div data-ng-include src="'/views/includes/connection.html'"></div>
1+
<div data-ng-include src="'views/includes/connection.html'"></div>
22
<div class="jumbotron">
33
<h1>Ooops!</h1>
44
<h2 translate class="text-muted">404 Page not found :(</h2>

public/views/address.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div data-ng-include src="'/views/includes/connection.html'"></div>
1+
<div data-ng-include src="'views/includes/connection.html'"></div>
22
<section data-ng-controller="AddressController" data-ng-init="findOne()">
33
<div class="secondary_navbar hidden-xs hidden-sm" scroll data-ng-class="{'hidden': !secondaryNavbar}" data-ng-show="address.addrStr" data-ng-init="hideSNavbar=0">
44
<div class="container" data-ng-if="!hideSNavbar">
@@ -74,7 +74,7 @@ <h3 translate>Unconfirmed</h3>
7474
</div>
7575
<div data-ng-if="address.addrStr" data-ng-controller="transactionsController" data-ng-init="load('address')">
7676
<h2 translate>Transactions</h2>
77-
<div data-ng-include src="'/views/transaction/list.html'" when-scrolled="loadMore()"></div>
77+
<div data-ng-include src="'views/transaction/list.html'" when-scrolled="loadMore()"></div>
7878
</div>
7979
</section>
8080

0 commit comments

Comments
 (0)