-
Notifications
You must be signed in to change notification settings - Fork 1.2k
version #43
version #43
Changes from 2 commits
f86cb1b
f7768b5
447f6a9
96ad02a
a4e210f
258e892
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
var Command = require('ronin').Command | ||
'use strict' | ||
|
||
const Command = require('ronin').Command | ||
|
||
module.exports = Command.extend({ | ||
desc: '', | ||
|
||
run: function (name) {} | ||
run: name => {} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
var Command = require('ronin').Command | ||
'use strict' | ||
|
||
const Command = require('ronin').Command | ||
|
||
module.exports = Command.extend({ | ||
desc: '', | ||
|
||
run: function (name) {} | ||
run: name => {} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
var Command = require('ronin').Command | ||
'use strict' | ||
|
||
const Command = require('ronin').Command | ||
const httpAPI = require('../../http-api') | ||
const debug = require('debug') | ||
let log = debug('cli:daemon') | ||
log.error = debug('cli:damon:error') | ||
|
||
module.exports = Command.extend({ | ||
desc: '', | ||
desc: 'Start a long-running daemon process', | ||
|
||
run: function (name) {} | ||
run: name => { | ||
httpAPI.start((err) => { | ||
if (err) { return log.error(err) } | ||
log('daemon started') | ||
}) | ||
} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
var Command = require('ronin').Command | ||
'use strict' | ||
|
||
const Command = require('ronin').Command | ||
|
||
module.exports = Command.extend({ | ||
desc: '', | ||
|
||
run: function (name) {} | ||
run: name => {} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
var Command = require('ronin').Command | ||
const Command = require('ronin').Command | ||
|
||
module.exports = Command.extend({ | ||
desc: '', | ||
|
||
run: function (name) {} | ||
run: name => {} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
var Command = require('ronin').Command | ||
var IPFS = require('../../ipfs-core') | ||
const Command = require('ronin').Command | ||
const IPFS = require('../../ipfs-core') | ||
const debug = require('debug') | ||
let log = debug('cli:id') | ||
log.error = debug('cli:id:error') | ||
|
||
module.exports = Command.extend({ | ||
desc: 'Shows IPFS Node ID info', | ||
|
@@ -11,12 +14,10 @@ module.exports = Command.extend({ | |
} | ||
}, | ||
|
||
run: function (name) { | ||
var node = new IPFS() | ||
node.id(function (err, id) { | ||
if (err) { | ||
return console.error(err) | ||
} | ||
run: name => { | ||
let node = new IPFS() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
node.id((err, id) => { | ||
if (err) { return log.error(err) } | ||
console.log(id) | ||
}) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
var Command = require('ronin').Command | ||
'use strict' | ||
|
||
const Command = require('ronin').Command | ||
|
||
module.exports = Command.extend({ | ||
desc: '', | ||
|
||
run: function (name) {} | ||
run: name => {} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
var Command = require('ronin').Command | ||
'use strict' | ||
|
||
const Command = require('ronin').Command | ||
|
||
module.exports = Command.extend({ | ||
desc: '', | ||
|
||
run: function (name) {} | ||
run: name => {} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
var Command = require('ronin').Command | ||
'use strict' | ||
|
||
const Command = require('ronin').Command | ||
|
||
module.exports = Command.extend({ | ||
desc: '', | ||
|
||
run: function (name) {} | ||
run: name => {} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
var Command = require('ronin').Command | ||
'use strict' | ||
|
||
const Command = require('ronin').Command | ||
|
||
module.exports = Command.extend({ | ||
desc: '', | ||
|
||
run: function (name) {} | ||
run: name => {} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
var Command = require('ronin').Command | ||
'use strict' | ||
|
||
const Command = require('ronin').Command | ||
|
||
module.exports = Command.extend({ | ||
desc: '', | ||
|
||
run: function (name) {} | ||
run: name => {} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
var Command = require('ronin').Command | ||
'use strict' | ||
|
||
const Command = require('ronin').Command | ||
|
||
module.exports = Command.extend({ | ||
desc: '', | ||
|
||
run: function (name) {} | ||
run: name => {} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict' | ||
|
||
const Hapi = require('hapi') | ||
const IPFS = require('../ipfs-core') | ||
const debug = require('debug') | ||
let log = debug('api') | ||
log.error = debug('api:error') | ||
|
||
exports = module.exports | ||
|
||
exports.start = callback => { | ||
// start IPFS and exports.ipfs = new IPFS() | ||
|
||
exports.ipfs = new IPFS() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, this looks like asking for trouble when the export is only available after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the .ipfs is to be used by the http-api resources, which are only loaded after start is called (from routes), so there is no conflict. Did I get your question right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kind of, but why not just pass these resources through explicitly, this could easily break, or be miss used by someone not understanding these exports |
||
|
||
var server = exports.server = new Hapi.Server({ | ||
connections: { | ||
routes: { | ||
cors: true | ||
} | ||
} | ||
}) | ||
|
||
server.connection({ | ||
port: 9000 | ||
}) | ||
|
||
// load routes | ||
require('./routes/version.js') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be much cleaner: server.route(require('./routes/version.js')
// version.js
var resources = require('./../resources')
module.exports = {
method: 'GET',
path: '/api/v0/version',
handler: resources.version.get
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is that "much" cleaner? If there was more than one route on that file I would have to go and server.route(require('./routes/version.js').routeA)
server.route(require('./routes/version.js').routeB)
// etc Meaning that I have to alter the route file and index.js, the way I have, I only have to open and modify one file. Also, having the server object available means I always have server methods at my hand. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not about that, could also change it to require('./routes/version.js').forEach(server.route.bind(server)
// version.js
module.exports = [
// my routes
] The main issue I have your current implementation is that it introduces a circular dependency from this file to the routes files. If you want to have the server object be available make it like this: require('./routes/version.js')(server)
// version.js
server.route({...}) that way the circular dependency is removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could DI the server obj (and the IPFS core object), but I kind of like making available by knowing where to pick it from other then move it around. I've been doing this for a while, if it becomes complicated over time, I will reconsider your suggestion :) |
||
|
||
server.start(err => { | ||
if (err) { return callback(err) } | ||
log('server started: ' + server.info.uri) | ||
callback() | ||
}) | ||
} | ||
|
||
exports.stop = () => { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exports.version = require('./version') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict' | ||
|
||
const ipfs = require('./../index.js').ipfs | ||
const boom = require('boom') | ||
|
||
exports = module.exports | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because although they point to the same thing initially, if not binded, once exports changes it will stop pointing to module.exports and therefore none of the functions that gets exported by more info and examples: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm but you don't use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not in this case, but it is kind of the same why I always add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay |
||
|
||
exports.get = (request, reply) => { | ||
ipfs.version((err, version) => { | ||
if (err) { return reply(boom.badRequest(err)) } | ||
return reply(version) | ||
}) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict' | ||
|
||
const server = require('./../index.js').server | ||
const resources = require('./../resources') | ||
|
||
server.route({ | ||
method: 'GET', | ||
path: '/api/v0/version', | ||
handler: resources.version.get | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
var os = require('os') | ||
'use strict' | ||
|
||
const os = require('os') | ||
|
||
exports = module.exports | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be
const