Created
March 4, 2017 13:00
-
-
Save lhartikk/410744c0699214daa9f7af506306cdb4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var initHttpServer = () => { | |
var app = express(); | |
app.use(bodyParser.json()); | |
app.get('/blocks', (req, res) => res.send(JSON.stringify(blockchain))); | |
app.post('/mineBlock', (req, res) => { | |
var newBlock = generateNextBlock(req.body.data); | |
addBlock(newBlock); | |
broadcast(responseLatestMsg()); | |
console.log('block added: ' + JSON.stringify(newBlock)); | |
res.send(); | |
}); | |
app.get('/peers', (req, res) => { | |
res.send(sockets.map(s => s._socket.remoteAddress + ':' + s._socket.remotePort)); | |
}); | |
app.post('/addPeer', (req, res) => { | |
connectToPeers([req.body.peer]); | |
res.send(); | |
}); | |
app.listen(http_port, () => console.log('Listening http on port: ' + http_port)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment