From 0b9076dde2f008299487b4f3d5be4afc2efa1849 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 4 Apr 2019 23:16:50 +0200 Subject: [PATCH] fix: print HTTP listeners only when run as daemon This changes behavior in web browser. Instead of printing to console.log, it uses proper debug-based logger. Old behavior in terminal (when run via `jsipfs daemon`) does not change. License: MIT Signed-off-by: Marcin Rataj --- src/cli/standalone-daemon.js | 2 +- src/http/index.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cli/standalone-daemon.js b/src/cli/standalone-daemon.js index fde604241e..e4d9c5c541 100644 --- a/src/cli/standalone-daemon.js +++ b/src/cli/standalone-daemon.js @@ -69,7 +69,7 @@ class StandaloneDaemon { this._ipfs = ipfs // start HTTP servers (if API or Gateway is enabled in options) - const httpApi = new HttpApi(ipfs, ipfsOpts) + const httpApi = new HttpApi(ipfs, Object.assign({ announceListeners: true }, ipfsOpts)) this._httpApi = await httpApi.start() this._log('started') diff --git a/src/http/index.js b/src/http/index.js index 69b305d43e..330ed923bd 100644 --- a/src/http/index.js +++ b/src/http/index.js @@ -77,14 +77,15 @@ class HttpApi { const gatewayAddrs = config.Addresses.Gateway this._gatewayServers = await serverCreator(gatewayAddrs, this._createGatewayServer, ipfs) + const announce = this._options.announceListeners ? ipfs._print : this._log this._apiServers.forEach(apiServer => { - ipfs._print('API listening on %s', apiServer.info.ma) + announce('API listening on %s', apiServer.info.ma.toString()) }) this._gatewayServers.forEach(gatewayServer => { - ipfs._print('Gateway (read only) listening on %s', gatewayServer.info.ma) + announce('Gateway (read only) listening on %s', gatewayServer.info.ma.toString()) }) this._apiServers.forEach(apiServer => { - ipfs._print('Web UI available at %s', toUri(apiServer.info.ma) + '/webui') + announce('Web UI available at %s', toUri(apiServer.info.ma) + '/webui') }) this._log('started') return this