From 9a1cc56bc1279ca3a4386f7c8dc76a62066d36c7 Mon Sep 17 00:00:00 2001 From: David Dias Date: Sat, 20 Feb 2016 15:46:28 +0000 Subject: [PATCH 01/14] daemon start and shutdown --- src/cli/commands/daemon.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/cli/commands/daemon.js b/src/cli/commands/daemon.js index f4ab32e09c..4ee301a7d7 100644 --- a/src/cli/commands/daemon.js +++ b/src/cli/commands/daemon.js @@ -4,15 +4,28 @@ const Command = require('ronin').Command const httpAPI = require('../../http-api') const debug = require('debug') const log = debug('cli:daemon') -log.error = debug('cli:damon:error') +log.error = debug('cli:daemon:error') module.exports = Command.extend({ desc: 'Start a long-running daemon process', run: name => { + console.log('Initializing daemon...') httpAPI.start((err) => { - if (err) { return log.error(err) } - log('daemon started') + if (err) { + return log.error(err) + } + console.log('Daemon is ready') + }) + + process.on('SIGINT', () => { + console.log('Received interrupt signal, shutting down..') + httpAPI.stop((err) => { + if (err) { + return log.error(err) + } + process.exit(0) + }) }) } }) From 39f518c61f0adcdfc763218970464bedfefe4bc8 Mon Sep 17 00:00:00 2001 From: David Dias Date: Sat, 20 Feb 2016 16:08:53 +0000 Subject: [PATCH 02/14] one conn for each (api and gateway) --- src/http-api/index.js | 46 ++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/http-api/index.js b/src/http-api/index.js index 6d66f0ed75..3c22d10c3d 100644 --- a/src/http-api/index.js +++ b/src/http-api/index.js @@ -11,27 +11,41 @@ exports = module.exports exports.start = callback => { // start IPFS and exports.ipfs = new IPFS() - exports.ipfs = new IPFS() + const ipfs = exports.ipfs = new IPFS() - var server = exports.server = new Hapi.Server({ - connections: { - routes: { - cors: true - } + ipfs.config.show((err, config) => { + if (err) { + return callback(err) } - }) - server.connection({ - port: 9001 - }) + // TODO: set up cors correctly, following config + var server = exports.server = new Hapi.Server({ + connections: { + routes: { + cors: true + } + } + }) + const api = config.Addresses.API.split('/') + const gateway = config.Addresses.Gateway.split('/') + + // select which connection with server.select(