Files: 7a7c971a8576fa166e3102de330a6e4c2be98c06 / tests / remote.js
560 bytesRaw
1 | const RadixTree = require('../') |
2 | |
3 | const cbor = require('borc') |
4 | const http = require('http') |
5 | |
6 | let tree |
7 | |
8 | const server = http.createServer(async (req, res) => { |
9 | const key = Buffer.from(req.url.slice(1), 'hex') |
10 | const value = await tree.graph._dag.get(key) |
11 | res.end(cbor.encode(value).toString('base64')) |
12 | }) |
13 | |
14 | module.exports = { |
15 | listen: (db, port = 3000) => { |
16 | server.listen(port, (err) => { |
17 | if (err) { return console.error(err) } |
18 | |
19 | tree = new RadixTree({db}) |
20 | |
21 | console.log(`server is listening on ${port}`) |
22 | }) |
23 | |
24 | return server |
25 | } |
26 | } |
27 |
Built with git-ssb-web