Conversation
|
Continuation of #21. :) |
|
bump |
|
Thanks for the bump @drbh. I'll be taking a closer look at this tomorrow. |
|
@drbh Would you mind either writing a positive test case or some unit test (which we'll need to merge anyway)? Another question I have is if we could include the orbit-db-http-server package here instead of copying the files over. Maybe there is something we can do on our end to get that merged and usable for you. I think adding an HTTP server is an extremely useful addition and besides just wanting to do it right I think we want to generalize this to be useful across all the orbit packages |
|
Happy to move the orbit-db-http-server repo if you want to continue it. Agreed with @aphelionz that making it generic and usable in other projects too would be the best way forward. |
|
|
||
| /* Export as Yargs command */ | ||
| exports.command = 'daemon' | ||
| exports.desc = 'Start a orbitdb daemon' |
There was a problem hiding this comment.
Minor grammar suggestion :)
| exports.desc = 'Start a orbitdb daemon' | |
| exports.desc = 'Start an orbitdb daemon' |
| const address = req.params[0] | ||
|
|
||
| // Get params on how we should output the results | ||
| const shouldStream = req.query.live || false |
There was a problem hiding this comment.
A more concise way to do it
| const shouldStream = req.query.live || false | |
| const shouldStream = Boolean(req.query.live) |
| const db = await req.orbitdb.open(address, { | ||
| create: false, | ||
| sync: true, | ||
| localOnly: req.query.live ? !req.query.live : true, |
There was a problem hiding this comment.
| localOnly: req.query.live ? !req.query.live : true, | |
| localOnly: !Boolean(req.query.live), |
| const defaultPort = 37373 | ||
| const defaultHost = "localhost" |
There was a problem hiding this comment.
Standard constants can be written in all caps like below
const DEFAULT_PORT = 37373
const DEFAULT_HOST = "localhost"
|
|
||
| return new Promise((resolve, reject) => { | ||
| // Start the HTTP server | ||
| let server = app.listen({ port: port, host: host }, async () => { |
There was a problem hiding this comment.
| let server = app.listen({ port: port, host: host }, async () => { | |
| let server = app.listen({ port, host }, async () => { |
| } | ||
| const err = false | ||
| if (err){ | ||
| reject(server) |
There was a problem hiding this comment.
Will this block of code ever execute? The err is set to false as always.
Copied files
server.jsadd.jscreate.jsget.jsfrom 3c691c032a047e99237af24af6956b9068c314e6 branch of orbit-db-http-server at https://github.com/haadcode/orbit-db-http-server.gitAdded a new file in commands that run the daemon. This currently runs in the foreground and can be canceled with CTL + C, also hard coded the port and host to remove unneeded files.
-added the files that the original PR was missing.