diff --git a/config/env/common.js b/config/env/common.js index 951f7d4..c1aca4f 100644 --- a/config/env/common.js +++ b/config/env/common.js @@ -54,6 +54,7 @@ export default { : 'demo', // IPFS settings. + useIpfs: process.env.DISABLE_IPFS ? false : true, // Disable IPFS flag isCircuitRelay: process.env.ENABLE_CIRCUIT_RELAY ? true : false, // SSL domain used for websocket connection via browsers. crDomain: process.env.CR_DOMAIN ? process.env.CR_DOMAIN : '', diff --git a/src/adapters/index.js b/src/adapters/index.js index 0e01599..df75773 100644 --- a/src/adapters/index.js +++ b/src/adapters/index.js @@ -50,7 +50,9 @@ class Adapters { // Start the IPFS node. // Do not start these adapters if this is an e2e test. if (this.config.env !== 'test') { - await this.ipfs.start() + if (this.config.useIpfs) { + await this.ipfs.start() + } } else { // These lines are here to ensure code coverage hits 100%. console.log('Not starting IPFS node since this is an e2e test.') diff --git a/src/controllers/index.js b/src/controllers/index.js index 3c1ecf4..117de46 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -6,28 +6,21 @@ // Public npm libraries. -// Load the Clean Architecture Adapters library +// Local libraries import Adapters from '../adapters/index.js' - -// Load the JSON RPC Controller. import JSONRPC from './json-rpc/index.js' - -// Load the Clean Architecture Use Case libraries. import UseCases from '../use-cases/index.js' - -// const useCases = new UseCases({ adapters }) - -// Load the REST API Controllers. import RESTControllers from './rest-api/index.js' - -// Load the time controller library import TimerControllers from './timer-controllers.js' +import config from '../../config/index.js' class Controllers { constructor (localConfig = {}) { + // Encapsulate dependencies this.adapters = new Adapters() this.useCases = new UseCases({ adapters: this.adapters }) this.timerControllers = new TimerControllers({ adapters: this.adapters, useCases: this.useCases }) + this.config = config } // Spin up any adapter libraries that have async startup needs. @@ -57,8 +50,10 @@ class Controllers { // Wait for any startup processes to complete for the Adapters libraries. // await this.adapters.start() - // Attach JSON RPC controllers - this.attachRPCControllers() + if (this.config.useIpfs) { + // Attach JSON RPC controllers + this.attachRPCControllers() + } // Attach and start the timer controllers this.timerControllers.startTimers() diff --git a/test/unit/adapters/adapters-index-unit.js b/test/unit/adapters/adapters-index-unit.js index 0899895..ee382e4 100644 --- a/test/unit/adapters/adapters-index-unit.js +++ b/test/unit/adapters/adapters-index-unit.js @@ -27,6 +27,8 @@ describe('#adapters', () => { it('should start the async adapters', async () => { // Mock dependencies uut.config.getJwtAtStartup = true + uut.config.useIpfs = true + uut.config.env = 'not-a-test' sandbox.stub(uut.fullStackJwt, 'getJWT').resolves() sandbox.stub(uut.fullStackJwt, 'instanceBchjs').resolves() sandbox.stub(uut.ipfs, 'start').resolves()