Add 'auto' setting for geth CORS and websockets origin

* 'auto' now supported for `rpcCorsDomain` and `wsOrigins` in the blockchain config.
* 'auto' set to the default value in blockchain config for test and demo apps.
This commit is contained in:
Eric Mastro 2018-04-26 21:37:00 +10:00
parent acf1fa427b
commit ef0bcbf405
7 changed files with 24 additions and 12 deletions

View File

@ -103,14 +103,14 @@ class GethCommands {
if (config.wsOrigins) { if (config.wsOrigins) {
if (config.wsOrigins === '*') { if (config.wsOrigins === '*') {
console.log('=================================='); console.log('==================================');
console.log('rpcCorsDomain set to *'); console.log('wsOrigins set to *');
console.log('make sure you know what you are doing'); console.log('make sure you know what you are doing');
console.log('=================================='); console.log('==================================');
} }
cmd += "--wsorigins \"" + config.wsOrigins + "\" "; cmd += "--wsorigins \"" + config.wsOrigins + "\" ";
} else { } else {
console.log('=================================='); console.log('==================================');
console.log('warning: cors is not set'); console.log('warning: wsOrigins is not set');
console.log('=================================='); console.log('==================================');
} }
} }

View File

@ -39,7 +39,19 @@ class Embark {
blockchain(env, client) { blockchain(env, client) {
this.context = [constants.contexts.blockchain]; this.context = [constants.contexts.blockchain];
return require('./cmds/blockchain/blockchain.js')(this.config.blockchainConfig, client, env).run(); let blockchainConfig = this.config.blockchainConfig;
let storageConfig = this.config.storageConfig;
let webServerConfig = this.config.webServerConfig;
if(blockchainConfig.rpcCorsDomain === 'auto') {
if(webServerConfig) blockchainConfig.rpcCorsDomain = `http://${webServerConfig.host}:${webServerConfig.port}`;
if(storageConfig) blockchainConfig.rpcCorsDomain += `${blockchainConfig.rpcCorsDomain.length ? ',' : ''}http://${storageConfig.host}:${storageConfig.port}`;
}
if(blockchainConfig.wsOrigins === 'auto') {
if(webServerConfig) blockchainConfig.wsOrigins = `http://${webServerConfig.host}:${webServerConfig.port}`;
if(storageConfig) blockchainConfig.wsOrigins += `${blockchainConfig.wsOrigins.length ? ',' : ''}http://${storageConfig.host}:${storageConfig.port}`;
}
return require('./cmds/blockchain/blockchain.js')(blockchainConfig, client, env).run();
} }
simulator(options) { simulator(options) {

View File

@ -9,12 +9,12 @@
"maxpeers": 0, "maxpeers": 0,
"rpcHost": "localhost", "rpcHost": "localhost",
"rpcPort": 8545, "rpcPort": 8545,
"rpcCorsDomain": "http://localhost:8000", "rpcCorsDomain": "auto",
"account": { "account": {
"password": "config/development/password" "password": "config/development/password"
}, },
"targetGasLimit": 8000000, "targetGasLimit": 8000000,
"wsOrigins": "http://localhost:8000", "wsOrigins": "auto",
"wsRPC": true, "wsRPC": true,
"wsHost": "localhost", "wsHost": "localhost",
"wsPort": 8546, "wsPort": 8546,

View File

@ -9,12 +9,12 @@
"maxpeers": 0, "maxpeers": 0,
"rpcHost": "localhost", "rpcHost": "localhost",
"rpcPort": 8545, "rpcPort": 8545,
"rpcCorsDomain": "http://localhost:8000", "rpcCorsDomain": "auto",
"account": { "account": {
"password": "config/development/password" "password": "config/development/password"
}, },
"targetGasLimit": 8000000, "targetGasLimit": 8000000,
"wsOrigins": "http://localhost:8000", "wsOrigins": "auto",
"wsRPC": true, "wsRPC": true,
"wsHost": "localhost", "wsHost": "localhost",
"wsPort": 8546, "wsPort": 8546,

View File

@ -7,7 +7,7 @@
"nodiscover": true, "nodiscover": true,
"rpcHost": "localhost", "rpcHost": "localhost",
"rpcPort": 8545, "rpcPort": 8545,
"rpcCorsDomain": "http://localhost:8000", "rpcCorsDomain": "auto",
"account": { "account": {
"password": "config/development/password" "password": "config/development/password"
} }

View File

@ -9,12 +9,12 @@
"maxpeers": 0, "maxpeers": 0,
"rpcHost": "localhost", "rpcHost": "localhost",
"rpcPort": 8545, "rpcPort": 8545,
"rpcCorsDomain": "http://localhost:8000", "rpcCorsDomain": "auto",
"account": { "account": {
"password": "development/password" "password": "development/password"
}, },
"targetGasLimit": 8000000, "targetGasLimit": 8000000,
"wsOrigins": "http://localhost:8000", "wsOrigins": "auto",
"wsRPC": true, "wsRPC": true,
"wsHost": "localhost", "wsHost": "localhost",
"wsPort": 8546 "wsPort": 8546

View File

@ -9,12 +9,12 @@
"maxpeers": 0, "maxpeers": 0,
"rpcHost": "localhost", "rpcHost": "localhost",
"rpcPort": 8545, "rpcPort": 8545,
"rpcCorsDomain": "http://localhost:8000", "rpcCorsDomain": "auto",
"account": { "account": {
"password": "config/development/password" "password": "config/development/password"
}, },
"targetGasLimit": 8000000, "targetGasLimit": 8000000,
"wsOrigins": "http://localhost:8000", "wsOrigins": "auto",
"wsRPC": true, "wsRPC": true,
"wsHost": "localhost", "wsHost": "localhost",
"wsPort": 8546 "wsPort": 8546