git ssb

0+

wanderer🌟 / js-dfinity-radix-tree



Tree: 523fd9bda6df579abb596ed6e04a5c19c32ef4c2

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