fix swarm spawn

This commit is contained in:
Jonathan Rainville 2018-05-28 15:37:25 -04:00
parent c86c50fb4e
commit d06a7f43ac
1 changed files with 23 additions and 8 deletions

View File

@ -1,6 +1,7 @@
const child_process = require('child_process');
const ProcessWrapper = require('../../process/processWrapper');
const constants = require('../../constants');
const fs = require('../../core/fs');
let swarmProcess;
@ -20,15 +21,27 @@ class SwarmProcess extends ProcessWrapper {
if (self.webServerConfig && self.webServerConfig && self.webServerConfig.host && self.webServerConfig.port) {
corsDomain = `http://${self.webServerConfig.host}:${self.webServerConfig.port}`;
}
const child = child_process.spawn(this.storageConfig.swarmPath || 'swarm',
[
`--bzzaccount ${this.storageConfig.account.address}`,
`--password ${this.storageConfig.account.password}`,
`--corsdomain ${corsDomain}`,
"--ens-api ''"
]);
const args = [
`--bzzaccount=${this.storageConfig.account.address}`,
`--password=${fs.dappPath(this.storageConfig.account.password)}`,
`--corsdomain=${corsDomain}`,
`--ens-api=''`
];
const child = child_process.spawn(this.storageConfig.swarmPath || 'swarm', args, {shell: true});
child.on('error', (err) => {
err = err.toString();
console.error('Swarm error: ', err);
});
let lastMessage;
child.stdout.on('data', (data) => {
data = data.toString();
console.log(`Swarm error: ${data}`);
});
// Geth logs appear in stderr somehow
child.stderr.on('data', (data) => {
data = data.toString();
if (!self.readyCalled && data.indexOf('Swarm http proxy started') > -1) {
self.readyCalled = true;
self.send({result: constants.storage.initiated});
@ -39,7 +52,9 @@ class SwarmProcess extends ProcessWrapper {
child.on('exit', (code) => {
if (code) {
console.error('Swarm exited with error code ' + code);
console.error(lastMessage);
if (lastMessage) {
console.error(lastMessage);
}
}
});
}