git ssb

0+

wanderer🌟 / js-dfinity-radix-tree



Tree: 7a7c971a8576fa166e3102de330a6e4c2be98c06

Files: 7a7c971a8576fa166e3102de330a6e4c2be98c06 / tests / remote.js

560 bytesRaw
1const RadixTree = require('../')
2
3const cbor = require('borc')
4const http = require('http')
5
6let tree
7
8const 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
14module.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