Files: 523fd9bda6df579abb596ed6e04a5c19c32ef4c2 / 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