diff --git a/lib/index.js b/lib/index.js index 43594413..41f93fc4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -91,7 +91,8 @@ class Embark { const storageProcessesLauncher = new StorageProcessesLauncher({ logger: engine.logger, events: engine.events, - storageConfig: engine.config.storageConfig + storageConfig: engine.config.storageConfig, + webServerConfig: engine.config.webServerConfig }); return storageProcessesLauncher.launchProcess(platform.toLowerCase(), (err) => { if (err) { diff --git a/lib/processes/storageProcesses/storageProcessesLauncher.js b/lib/processes/storageProcesses/storageProcessesLauncher.js index ceecf9f5..2c40a1ea 100644 --- a/lib/processes/storageProcesses/storageProcessesLauncher.js +++ b/lib/processes/storageProcesses/storageProcessesLauncher.js @@ -8,6 +8,7 @@ class StorageProcessesLauncher { this.logger = options.logger; this.events = options.events; this.storageConfig = options.storageConfig; + this.webServerConfig = options.webServerConfig; this.processes = {}; } @@ -33,7 +34,12 @@ class StorageProcessesLauncher { silent: true, exitCallback: self.processExited.bind(this, storageName) }); - self.processes[storageName].send({action: constants.blockchain.init, options: {storageConfig: self.storageConfig}}); + self.processes[storageName].send({ + action: constants.blockchain.init, options: { + storageConfig: self.storageConfig, + webServerConfig: self.webServerConfig + } + }); self.processes[storageName].on('result', constants.storage.initiated, (msg) => { if (msg.error) { diff --git a/lib/processes/storageProcesses/swarm.js b/lib/processes/storageProcesses/swarm.js index 05db51f8..b622404e 100644 --- a/lib/processes/storageProcesses/swarm.js +++ b/lib/processes/storageProcesses/swarm.js @@ -8,6 +8,7 @@ class SwarmProcess extends ProcessWrapper { constructor(options) { super(); this.storageConfig = options.storageConfig; + this.webServerConfig = options.webServerConfig; } startSwarmDaemon() { @@ -15,8 +16,12 @@ class SwarmProcess extends ProcessWrapper { if (!this.storageConfig.account || !this.storageConfig.account.address || !this.storageConfig.account.password) { return 'Account address and password are needed in the storage config to start the Swarm process'; } + let corsDomain = 'http://localhost:8000'; + if (self.webServerConfig && self.webServerConfig && self.webServerConfig.host && self.webServerConfig.port) { + corsDomain = `http://${self.webServerConfig.host}:${self.webServerConfig.port}`; + } const child = shelljs.exec( - `${this.storageConfig.swarmPath || 'swarm'} --bzzaccount ${this.storageConfig.account.address} --password ${this.storageConfig.account.password} --corsdomain http://localhost:8000 --ens-api ''`, + `${this.storageConfig.swarmPath || 'swarm'} --bzzaccount ${this.storageConfig.account.address} --password ${this.storageConfig.account.password} --corsdomain ${corsDomain} --ens-api ''`, {silent: true}, (err, _stdout, _stderr) => { if (err) {