diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000000000000000000000000000000000000..a80006e34c0ec34f005885fb38b138339e25f7b4 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +jsPDF.min.js +SlateEditor/ +assets diff --git a/.eslintrc b/.eslintrc index b1ae21095e623573e9d63ac10fc49beb7cd514d4..1335cb289f26a3f2c4c257343c31a598fd8b03cf 100644 --- a/.eslintrc +++ b/.eslintrc @@ -12,11 +12,6 @@ find node_modules/eslint-config-airbnb -name '*.js'|xargs sed -i "s/': 2/': 1/" "node": true, "es6": true }, - "ignorePatterns": [ - "jsPDF.min.js", - "SlateEditor/", - "assets" - ], "rules": { "max-len": 0, /*[1, 160, 4],*/ diff --git a/config/custom-environment-variables.json b/config/custom-environment-variables.json index bf5c3a36896c3909546ea4eabd5e217dbbce67cd..17c4db2bea77b470369254c286b924d5f3968c28 100644 --- a/config/custom-environment-variables.json +++ b/config/custom-environment-variables.json @@ -33,6 +33,7 @@ "steemd_connection_server": "SDC_SERVER_STEEMD_URL", "steemd_use_appbase": "SDC_USE_APPBASE", "chain_id": "SDC_CHAIN_ID", + "alternative_api_endpoints": "SDC_ALT_API_ENDPOINTS", "address_prefix": "SDC_ADDRESS_PREFIX", "conveyor_posting_wif": "CONVEYOR_POSTING_WIF", "conveyor_username": "CONVEYOR_USERNAME", @@ -47,5 +48,5 @@ "steem_market_token": "STEEM_MARKET_TOKEN", "cookie_consent_enabled": "SDC_ENABLE_COOKIE_CONSENT", "cookie_consent_api_key": "SDC_COOKIE_CONSENT_KEY", - "esteem_elastic_search_api_key": "ESTEEM_ELASTIC_SEARCH_API_KEY" + "esteem_elastic_search_api_key": "ESTEEM_ELASTIC_SEARCH_API_KEY" } diff --git a/config/default.json b/config/default.json index f1b273eda1c234a9684cd5fc9c925cd4654945be..5b200c2d30d239efa9f85df2ffaf8771db30da02 100644 --- a/config/default.json +++ b/config/default.json @@ -39,7 +39,7 @@ "steemd_connection_server": "https://api.hive.blog", "steemd_use_appbase": false, "chain_id": "0000000000000000000000000000000000000000000000000000000000000000", - "alternative_api_endpoints": ["https://api.hive.blog", "https://anyx.io"], + "alternative_api_endpoints": "https://api.hive.blog https://anyx.io", "failover_threshold": 3, "address_prefix": "STM", "conveyor_posting_wif": false, diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 58c672953f384569e0275228298af475cfc5cebe..ab81dea143276a58ff911da97bbf729e955ead32 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -29,7 +29,8 @@ services: SDC_SITE_DOMAIN: hive.blog SDC_IMAGE_PROXY_PREFIX: https://images.hive.blog/ SDC_UPLOAD_IMAGE_URL: https://images.hive.blog - SDC_HELMET_CONNECTSRC: "'self' hive.blog https://hive.blog https://api.hive.blog https://anyx.io api.blocktrades.us https://images.hive.blog" + SDC_ALT_API_ENDPOINTS: "https://api.hive.blog https://anyx.io https://api.openhive.network https://api.hivekings.com" + SDC_HELMET_CONNECTSRC: "'self' hive.blog https://hive.blog https://images.hive.blog https://api.hive.blog https://anyx.io https://api.openhive.network https://api.hivekings.com" WALLET_URL: https://wallet.hive.blog networks: - reverse-proxy diff --git a/src/app/Main.js b/src/app/Main.js index 5d632dbad9185fd2ff8321236180403c1a7fdbaf..6df66884b7ecc126ed463dd7c0f04b1dfe9fcdf3 100644 --- a/src/app/Main.js +++ b/src/app/Main.js @@ -83,24 +83,23 @@ function runApp(initial_state) { cmd(CMD_LOG_O); } - const config = initial_state.offchain.config; + const { config } = initial_state.offchain; + const alternativeApiEndpoints = config.alternative_api_endpoints; + const currentApiEndpoint = + localStorage.getItem('user_preferred_api_endpoint') === null + ? config.steemd_connection_client + : localStorage.getItem('user_preferred_api_endpoint'); + steem.api.setOptions({ - url: - localStorage.getItem('user_preferred_api_endpoint') === null - ? config.steemd_connection_client - : localStorage.getItem('user_preferred_api_endpoint'), + url: currentApiEndpoint, retry: true, useAppbaseApi: !!config.steemd_use_appbase, - alternative_api_endpoints: config.alternative_api_endpoints, + alternative_api_endpoints: alternativeApiEndpoints, failover_threshold: config.failover_threshold, }); steem.config.set('address_prefix', config.address_prefix); steem.config.set('chain_id', config.chain_id); - steem.config.set('failover_threshold', config.failover_threshold); - steem.config.set( - 'alternative_api_endpoints', - config.alternative_api_endpoints - ); + window.$STM_Config = config; plugins(config); if (initial_state.offchain.serverBusy) { diff --git a/src/app/components/modules/Settings.jsx b/src/app/components/modules/Settings.jsx index 19c8df907943188cf53c9d9f3d35de7c1ee5dfea..98ef357bfbaee3e043b8fe8132331f88cf72838c 100644 --- a/src/app/components/modules/Settings.jsx +++ b/src/app/components/modules/Settings.jsx @@ -233,22 +233,38 @@ class Settings extends React.Component { this.props.setUserPreferences(userPreferences); }; + getPreferredApiEndpoint = () => { + let preferred_api_endpoint = $STM_Config.steemd_connection_client; + + if ( + typeof window !== 'undefined' && + localStorage.getItem('user_preferred_api_endpoint') + ) { + preferred_api_endpoint = localStorage.getItem( + 'user_preferred_api_endpoint' + ); + } + + return preferred_api_endpoint; + }; + generateAPIEndpointOptions = () => { - let endpoints = api.config.get('alternative_api_endpoints'); - let preferred_api_endpoint = ''; - if (typeof window !== 'undefined') - preferred_api_endpoint = - localStorage.getItem('user_preferred_api_endpoint') === null - ? 'https://api.hive.blog' - : localStorage.getItem('user_preferred_api_endpoint'); + const endpoints = api.config.get('alternative_api_endpoints'); + if (endpoints === null || endpoints === undefined) { return null; } - let entries = []; - for (var endpoint of endpoints) { - if (endpoint === preferred_api_endpoint) continue; //this one is always present even if the api config call fails - let entry = <option value={endpoint}>{endpoint}</option>; - entries.push(entry); + + const preferred_api_endpoint = this.getPreferredApiEndpoint(); + const entries = []; + for (let ei = 0; ei < endpoints.length; ei += 1) { + const endpoint = endpoints[ei]; + + //this one is always present even if the api config call fails + if (endpoint !== preferred_api_endpoint) { + const entry = <option value={endpoint}>{endpoint}</option>; + entries.push(entry); + } } return entries; }; @@ -292,13 +308,7 @@ class Settings extends React.Component { progress, } = this.state; - let preferred_api_endpoint = 'https://api.hive.blog'; - if (typeof window !== 'undefined') { - preferred_api_endpoint = - localStorage.getItem('user_preferred_api_endpoint') === null - ? 'https://api.hive.blog' - : localStorage.getItem('user_preferred_api_endpoint'); - } + const preferred_api_endpoint = this.getPreferredApiEndpoint(); return ( <div className="Settings"> diff --git a/src/server/index.js b/src/server/index.js index 41cd23467a351839e1566f7881f1a76b7e234118..2793ec93d0b4348fc292dae0cebec11e505c7e85 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -16,6 +16,10 @@ require('module').Module._initPaths(); // Load Intl polyfill // require('utils/intl-polyfill')(require('./config/init').locales); +const alternativeApiEndpoints = config + .get('alternative_api_endpoints') + .split(' '); + global.$STM_Config = { fb_app: config.get('facebook_app_id'), steemd_connection_client: config.get('steemd_connection_client'), @@ -31,7 +35,7 @@ global.$STM_Config = { google_analytics_id: config.get('google_analytics_id'), wallet_url: config.get('wallet_url'), failover_threshold: config.get('failover_threshold'), - alternative_api_endpoints: config.get('alternative_api_endpoints'), + alternative_api_endpoints: alternativeApiEndpoints, }; const WebpackIsomorphicTools = require('webpack-isomorphic-tools'); @@ -52,16 +56,11 @@ global.webpackIsomorphicTools.server(ROOT, () => { randomize: true, }, useAppbaseApi: !!config.steemd_use_appbase, - alternative_api_endpoints: config.get('alternative_api_endpoints'), + alternative_api_endpoints: alternativeApiEndpoints, failover_threshold: config.get('failover_threshold'), }); steem.config.set('address_prefix', config.get('address_prefix')); steem.config.set('chain_id', config.get('chain_id')); - steem.config.set( - 'alternative_api_endpoints', - config.get('alternative_api_endpoints') - ); - steem.config.set('failover_threshold', config.get('failover_threshold')); // const CliWalletClient = require('shared/api_client/CliWalletClient').default; // if (process.env.NODE_ENV === 'production') connect_promises.push(CliWalletClient.instance().connect_promise());