Merge pull request #381 from embark-framework/features/cors-auto

Add 'auto' setting for geth CORS and websockets origin
This commit is contained in:
Iuri Matias 2018-04-26 10:14:06 -04:00 committed by GitHub
commit 9e91915bce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 11 deletions

View File

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

View File

@ -39,7 +39,19 @@ class Embark {
blockchain(env, client) {
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) {

View File

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

View File

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

View File

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

View File

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