From 1bafc41d9700f923f7649f51e62730d8f3e4d4d4 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 9 Jan 2019 09:21:16 -0500 Subject: [PATCH] change to use an object instead and change templates --- src/lib/core/config.js | 12 ++++++++---- templates/boilerplate/config/blockchain.js | 12 ++++++++---- templates/demo/config/blockchain.js | 12 ++++++++---- test_apps/embark_demo/config/blockchain.js | 12 ++++++++---- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/lib/core/config.js b/src/lib/core/config.js index cdbbb930f..756b278da 100644 --- a/src/lib/core/config.js +++ b/src/lib/core/config.js @@ -165,13 +165,17 @@ Config.prototype._updateBlockchainCors = function(){ let cors = corsParts.join(','); if (blockchainConfig.rpcCorsDomain === 'auto') { blockchainConfig.rpcCorsDomain = cors; - } else if (blockchainConfig.rpcCorsDomain.indexOf('auto') > -1) { - blockchainConfig.rpcCorsDomain = blockchainConfig.rpcCorsDomain.replace('auto', cors); + } else if (typeof blockchainConfig.rpcCorsDomain === 'object') { + let tempCors = blockchainConfig.rpcCorsDomain.auto ? corsParts : []; + tempCors = tempCors.concat(blockchainConfig.rpcCorsDomain.additionalCors || []); + blockchainConfig.rpcCorsDomain = tempCors.join(','); } if (blockchainConfig.wsOrigins === 'auto') { blockchainConfig.wsOrigins = cors; - } else if (blockchainConfig.wsOrigins.indexOf('auto') > -1) { - blockchainConfig.wsOrigins = blockchainConfig.wsOrigins.replace('auto', cors); + } else if (typeof blockchainConfig.wsOrigins === 'object') { + let tempCors = blockchainConfig.wsOrigins.auto ? corsParts : []; + tempCors = tempCors.concat(blockchainConfig.wsOrigins.additionalCors || []); + blockchainConfig.wsOrigins = tempCors.join(','); } }; diff --git a/templates/boilerplate/config/blockchain.js b/templates/boilerplate/config/blockchain.js index d29cc0c1f..846e1d4ff 100644 --- a/templates/boilerplate/config/blockchain.js +++ b/templates/boilerplate/config/blockchain.js @@ -4,11 +4,15 @@ module.exports = { enabled: true, rpcHost: "localhost", // HTTP-RPC server listening interface (default: "localhost") rpcPort: 8545, // HTTP-RPC server listening port (default: 8545) - rpcCorsDomain: "auto", // Comma separated list of domains from which to accept cross origin requests (browser enforced) - // When set to "auto", Embark will automatically set the cors to the address of the webserver + rpcCorsDomain: { // Domains from which to accept cross origin requests (browser enforced). This can also be a comma separated list + auto: true, // When "auto" is true, Embark will automatically set the cors to the address of the webserver + additionalCors: [] // Additional CORS domains to add to the list. If "auto" is false, only those will be added + }, wsRPC: true, // Enable the WS-RPC server - wsOrigins: "auto", // Origins from which to accept websockets requests - // When set to "auto", Embark will automatically set the cors to the address of the webserver + wsOrigins: { // Same thing as "rpcCorsDomain", but for WS origins + auto: true, + additionalCors: [] + }, wsHost: "localhost", // WS-RPC server listening interface (default: "localhost") wsPort: 8546 // WS-RPC server listening port (default: 8546) diff --git a/templates/demo/config/blockchain.js b/templates/demo/config/blockchain.js index 6e7192222..dac952306 100644 --- a/templates/demo/config/blockchain.js +++ b/templates/demo/config/blockchain.js @@ -4,11 +4,15 @@ module.exports = { enabled: true, rpcHost: "localhost", // HTTP-RPC server listening interface (default: "localhost") rpcPort: 8545, // HTTP-RPC server listening port (default: 8545) - rpcCorsDomain: "auto", // Comma separated list of domains from which to accept cross origin requests (browser enforced) - // When set to "auto", Embark will automatically set the cors to the address of the webserver + rpcCorsDomain: { // Domains from which to accept cross origin requests (browser enforced). This can also be a comma separated list + auto: true, // When "auto" is true, Embark will automatically set the cors to the address of the webserver + additionalCors: [] // Additional CORS domains to add to the list. If "auto" is false, only those will be added + }, wsRPC: true, // Enable the WS-RPC server - wsOrigins: "auto", // Origins from which to accept websockets requests - // When set to "auto", Embark will automatically set the cors to the address of the webserver + wsOrigins: { // Same thing as "rpcCorsDomain", but for WS origins + auto: true, + additionalCors: [] + }, wsHost: "localhost", // WS-RPC server listening interface (default: "localhost") wsPort: 8546 // WS-RPC server listening port (default: 8546) diff --git a/test_apps/embark_demo/config/blockchain.js b/test_apps/embark_demo/config/blockchain.js index 98689f9cd..d48bf1ad4 100644 --- a/test_apps/embark_demo/config/blockchain.js +++ b/test_apps/embark_demo/config/blockchain.js @@ -4,11 +4,15 @@ module.exports = { enabled: true, rpcHost: "localhost", // HTTP-RPC server listening interface (default: "localhost") rpcPort: 8545, // HTTP-RPC server listening port (default: 8545) - rpcCorsDomain: "auto", // Comma separated list of domains from which to accept cross origin requests (browser enforced) - // When set to "auto", Embark will automatically set the cors to the address of the webserver + rpcCorsDomain: { // Domains from which to accept cross origin requests (browser enforced). This can also be a comma separated list + auto: true, // When "auto" is true, Embark will automatically set the cors to the address of the webserver + additionalCors: [] // Additional CORS domains to add to the list. If "auto" is false, only those will be added + }, wsRPC: true, // Enable the WS-RPC server - wsOrigins: "auto", // Origins from which to accept websockets requests - // When set to "auto", Embark will automatically set the cors to the address of the webserver + wsOrigins: { // Same thing as "rpcCorsDomain", but for WS origins + auto: true, + additionalCors: [] + }, wsHost: "localhost", // WS-RPC server listening interface (default: "localhost") wsPort: 8546 // WS-RPC server listening port (default: 8546) },