forked from ArkEcosystemArchive/rpc-server
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (22 loc) · 969 Bytes
/
server.js
File metadata and controls
31 lines (22 loc) · 969 Bytes
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
var restify = require('restify');
var account = require('./src/account');
var transaction = require('./src/transaction');
var network = require('./src/network');
function restrictToLocalhost(req, res, next){
if(req.connection.remoteAddress == "::1" || req.connection.remoteAddress == "127.0.0.1" || req.connection.remoteAddress == "::ffff:127.0.0.1")
next();
else res.end();
}
var server = restify.createServer();
server.use(restrictToLocalhost);
server.use(restify.plugins.bodyParser({mapParams: true}));
server.use(network.connect);
server.get('/:network/account/:address', account.get);
server.post('/:network/account', account.create);
server.get('/:network/transactions/:address', account.getTransactions);
server.post('/:network/transaction', transaction.create);
server.post('/:network/broadcast', transaction.broadcast);
server.listen(8080, function() {
console.log('%s listening at %s', server.name, server.url);
});
module.exports = server;