mirror of https://github.com/embarklabs/embark.git
Support for embark-status plugin
Added request to update cors from a plugin (affects blockchain client and storage client).
This commit is contained in:
parent
870d9a814a
commit
2d19d12e39
|
@ -7,6 +7,7 @@ const deepEqual = require('deep-equal');
|
||||||
const web3 = require('web3');
|
const web3 = require('web3');
|
||||||
const constants = require('../constants');
|
const constants = require('../constants');
|
||||||
const {canonicalHost, defaultHost} = require('../utils/host');
|
const {canonicalHost, defaultHost} = require('../utils/host');
|
||||||
|
const cloneDeep = require('lodash.clonedeep');
|
||||||
|
|
||||||
const DEFAULT_CONFIG_PATH = 'config/';
|
const DEFAULT_CONFIG_PATH = 'config/';
|
||||||
const unitRegex = /([0-9]+) ([a-zA-Z]+)/;
|
const unitRegex = /([0-9]+) ([a-zA-Z]+)/;
|
||||||
|
@ -29,6 +30,12 @@ var Config = function(options) {
|
||||||
this.embarkConfig = {};
|
this.embarkConfig = {};
|
||||||
this.context = options.context || [constants.contexts.any];
|
this.context = options.context || [constants.contexts.any];
|
||||||
this.shownNoAccountConfigMsg = false; // flag to ensure "no account config" message is only displayed once to the user
|
this.shownNoAccountConfigMsg = false; // flag to ensure "no account config" message is only displayed once to the user
|
||||||
|
this.corsParts = [];
|
||||||
|
|
||||||
|
this.events.setCommandHandler("config:cors:add", (url) => {
|
||||||
|
this.corsParts.push(url);
|
||||||
|
this._updateBlockchainCors();
|
||||||
|
});
|
||||||
|
|
||||||
self.events.setCommandHandler("config:contractsConfig", (cb) => {
|
self.events.setCommandHandler("config:contractsConfig", (cb) => {
|
||||||
cb(self.contractsConfig);
|
cb(self.contractsConfig);
|
||||||
|
@ -104,7 +111,7 @@ Config.prototype._updateBlockchainCors = function(){
|
||||||
let blockchainConfig = this.blockchainConfig;
|
let blockchainConfig = this.blockchainConfig;
|
||||||
let storageConfig = this.storageConfig;
|
let storageConfig = this.storageConfig;
|
||||||
let webServerConfig = this.webServerConfig;
|
let webServerConfig = this.webServerConfig;
|
||||||
let corsParts = [];
|
let corsParts = cloneDeep(this.corsParts);
|
||||||
|
|
||||||
if(webServerConfig && webServerConfig.host) {
|
if(webServerConfig && webServerConfig.host) {
|
||||||
corsParts.push(utils.buildUrlFromConfig(webServerConfig));
|
corsParts.push(utils.buildUrlFromConfig(webServerConfig));
|
||||||
|
@ -233,6 +240,8 @@ Config.prototype.loadBlockchainConfigFile = function() {
|
||||||
);
|
);
|
||||||
this.shownNoAccountConfigMsg = true;
|
this.shownNoAccountConfigMsg = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.events.emit('config:load:blockchain', this.blockchainConfig);
|
||||||
};
|
};
|
||||||
|
|
||||||
Config.prototype.loadContractsConfigFile = function() {
|
Config.prototype.loadContractsConfigFile = function() {
|
||||||
|
@ -288,6 +297,8 @@ Config.prototype.loadContractsConfigFile = function() {
|
||||||
if (!deepEqual(newContractsConfig, this.contractsConfig)) {
|
if (!deepEqual(newContractsConfig, this.contractsConfig)) {
|
||||||
this.contractsConfig = newContractsConfig;
|
this.contractsConfig = newContractsConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.events.emit('config:load:contracts', this.contractsConfig);
|
||||||
};
|
};
|
||||||
|
|
||||||
Config.prototype.loadExternalContractsFiles = function() {
|
Config.prototype.loadExternalContractsFiles = function() {
|
||||||
|
@ -393,6 +404,8 @@ Config.prototype.loadWebServerConfigFile = function() {
|
||||||
} else {
|
} else {
|
||||||
this.webServerConfig = webServerConfig;
|
this.webServerConfig = webServerConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.events.emit('config:load:webserver', this.webServerConfig);
|
||||||
};
|
};
|
||||||
|
|
||||||
Config.prototype.loadEmbarkConfigFile = function() {
|
Config.prototype.loadEmbarkConfigFile = function() {
|
||||||
|
|
|
@ -115,7 +115,8 @@ class IPFS {
|
||||||
events: self.events,
|
events: self.events,
|
||||||
storageConfig: self.storageConfig,
|
storageConfig: self.storageConfig,
|
||||||
webServerConfig: self.webServerConfig,
|
webServerConfig: self.webServerConfig,
|
||||||
blockchainConfig: self.blockchainConfig
|
blockchainConfig: self.blockchainConfig,
|
||||||
|
corsParts: self.embark.config.corsParts
|
||||||
});
|
});
|
||||||
self.logger.trace(`Storage module: Launching ipfs process...`);
|
self.logger.trace(`Storage module: Launching ipfs process...`);
|
||||||
return storageProcessesLauncher.launchProcess('ipfs', callback);
|
return storageProcessesLauncher.launchProcess('ipfs', callback);
|
||||||
|
|
|
@ -4,6 +4,7 @@ const utils = require('../../utils/utils');
|
||||||
const ProcessLauncher = require('../../core/processes/processLauncher');
|
const ProcessLauncher = require('../../core/processes/processLauncher');
|
||||||
const constants = require('../../constants');
|
const constants = require('../../constants');
|
||||||
const {canonicalHost} = require('../../utils/host');
|
const {canonicalHost} = require('../../utils/host');
|
||||||
|
const cloneDeep = require('lodash.clonedeep');
|
||||||
|
|
||||||
let References = {
|
let References = {
|
||||||
ipfs: 'https://ipfs.io/docs/install/',
|
ipfs: 'https://ipfs.io/docs/install/',
|
||||||
|
@ -18,6 +19,7 @@ class StorageProcessesLauncher {
|
||||||
this.webServerConfig = options.webServerConfig;
|
this.webServerConfig = options.webServerConfig;
|
||||||
this.blockchainConfig = options.blockchainConfig;
|
this.blockchainConfig = options.blockchainConfig;
|
||||||
this.processes = {};
|
this.processes = {};
|
||||||
|
this.corsParts = options.corsParts || [];
|
||||||
|
|
||||||
this.cors = this.buildCors();
|
this.cors = this.buildCors();
|
||||||
|
|
||||||
|
@ -30,7 +32,7 @@ class StorageProcessesLauncher {
|
||||||
|
|
||||||
buildCors()
|
buildCors()
|
||||||
{
|
{
|
||||||
let corsParts = [];
|
let corsParts = cloneDeep(this.corsParts);
|
||||||
// add our webserver CORS
|
// add our webserver CORS
|
||||||
if(this.webServerConfig.enabled){
|
if(this.webServerConfig.enabled){
|
||||||
if (this.webServerConfig && this.webServerConfig.host) {
|
if (this.webServerConfig && this.webServerConfig.host) {
|
||||||
|
|
|
@ -97,7 +97,8 @@ class Swarm {
|
||||||
events: self.events,
|
events: self.events,
|
||||||
storageConfig: self.storageConfig,
|
storageConfig: self.storageConfig,
|
||||||
webServerConfig: self.webServerConfig,
|
webServerConfig: self.webServerConfig,
|
||||||
blockchainConfig: self.blockchainConfig
|
blockchainConfig: self.blockchainConfig,
|
||||||
|
corsParts: self.embark.config.corsParts
|
||||||
});
|
});
|
||||||
self.logger.trace(`Storage module: Launching swarm process...`);
|
self.logger.trace(`Storage module: Launching swarm process...`);
|
||||||
return storageProcessesLauncher.launchProcess('swarm', callback);
|
return storageProcessesLauncher.launchProcess('swarm', callback);
|
||||||
|
|
Loading…
Reference in New Issue