Skip to content

Commit 9e91915

Browse files
authored
Merge pull request #381 from embark-framework/features/cors-auto
Add 'auto' setting for geth CORS and websockets origin
2 parents acf1fa4 + 18e8f5c commit 9e91915

File tree

6 files changed

+23
-11
lines changed

6 files changed

+23
-11
lines changed

lib/cmds/blockchain/geth_commands.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ class GethCommands {
103103
if (config.wsOrigins) {
104104
if (config.wsOrigins === '*') {
105105
console.log('==================================');
106-
console.log('rpcCorsDomain set to *');
106+
console.log('wsOrigins set to *');
107107
console.log('make sure you know what you are doing');
108108
console.log('==================================');
109109
}
110110
cmd += "--wsorigins \"" + config.wsOrigins + "\" ";
111111
} else {
112112
console.log('==================================');
113-
console.log('warning: cors is not set');
113+
console.log('warning: wsOrigins is not set');
114114
console.log('==================================');
115115
}
116116
}

lib/index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,19 @@ class Embark {
3939

4040
blockchain(env, client) {
4141
this.context = [constants.contexts.blockchain];
42-
return require('./cmds/blockchain/blockchain.js')(this.config.blockchainConfig, client, env).run();
42+
let blockchainConfig = this.config.blockchainConfig;
43+
let storageConfig = this.config.storageConfig;
44+
let webServerConfig = this.config.webServerConfig;
45+
46+
if(blockchainConfig.rpcCorsDomain === 'auto') {
47+
if(webServerConfig) blockchainConfig.rpcCorsDomain = `http://${webServerConfig.host}:${webServerConfig.port}`;
48+
if(storageConfig) blockchainConfig.rpcCorsDomain += `${blockchainConfig.rpcCorsDomain.length ? ',' : ''}http://${storageConfig.host}:${storageConfig.port}`;
49+
}
50+
if(blockchainConfig.wsOrigins === 'auto') {
51+
if(webServerConfig) blockchainConfig.wsOrigins = `http://${webServerConfig.host}:${webServerConfig.port}`;
52+
if(storageConfig) blockchainConfig.wsOrigins += `${blockchainConfig.wsOrigins.length ? ',' : ''}http://${storageConfig.host}:${storageConfig.port}`;
53+
}
54+
return require('./cmds/blockchain/blockchain.js')(blockchainConfig, client, env).run();
4355
}
4456

4557
simulator(options) {

templates/boilerplate/config/blockchain.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
"maxpeers": 0,
1010
"rpcHost": "localhost",
1111
"rpcPort": 8545,
12-
"rpcCorsDomain": "http://localhost:8000",
12+
"rpcCorsDomain": "auto",
1313
"account": {
1414
"password": "config/development/password"
1515
},
1616
"targetGasLimit": 8000000,
17-
"wsOrigins": "http://localhost:8000",
17+
"wsOrigins": "auto",
1818
"wsRPC": true,
1919
"wsHost": "localhost",
2020
"wsPort": 8546,

templates/demo/config/blockchain.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
"maxpeers": 0,
1010
"rpcHost": "localhost",
1111
"rpcPort": 8545,
12-
"rpcCorsDomain": "http://localhost:8000",
12+
"rpcCorsDomain": "auto",
1313
"account": {
1414
"password": "config/development/password"
1515
},
1616
"targetGasLimit": 8000000,
17-
"wsOrigins": "http://localhost:8000",
17+
"wsOrigins": "auto",
1818
"wsRPC": true,
1919
"wsHost": "localhost",
2020
"wsPort": 8546,

test_apps/contracts_app/blockchain.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
"maxpeers": 0,
1010
"rpcHost": "localhost",
1111
"rpcPort": 8545,
12-
"rpcCorsDomain": "http://localhost:8000",
12+
"rpcCorsDomain": "auto",
1313
"account": {
1414
"password": "development/password"
1515
},
1616
"targetGasLimit": 8000000,
17-
"wsOrigins": "http://localhost:8000",
17+
"wsOrigins": "auto",
1818
"wsRPC": true,
1919
"wsHost": "localhost",
2020
"wsPort": 8546

test_apps/test_app/config/blockchain.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
"maxpeers": 0,
1010
"rpcHost": "localhost",
1111
"rpcPort": 8545,
12-
"rpcCorsDomain": "http://localhost:8000",
12+
"rpcCorsDomain": "auto",
1313
"account": {
1414
"password": "config/development/password"
1515
},
1616
"targetGasLimit": 8000000,
17-
"wsOrigins": "http://localhost:8000",
17+
"wsOrigins": "auto",
1818
"wsRPC": true,
1919
"wsHost": "localhost",
2020
"wsPort": 8546

0 commit comments

Comments
 (0)