Skip to content
Snippets Groups Projects
Commit cdc05288 authored by Bartłomiej Górnicki's avatar Bartłomiej Górnicki
Browse files

Merge branch 'alt-endpoint-env' into 'develop'

Make alternate API endpoints customisable via env variable

See merge request !54
parents bc738dd2 ffd00cc1
No related branches found
No related tags found
2 merge requests!63chore: update master with latests fixes and features from develop,!54Make alternate API endpoints customisable via env variable
jsPDF.min.js
SlateEditor/
assets
...@@ -12,11 +12,6 @@ find node_modules/eslint-config-airbnb -name '*.js'|xargs sed -i "s/': 2/': 1/" ...@@ -12,11 +12,6 @@ find node_modules/eslint-config-airbnb -name '*.js'|xargs sed -i "s/': 2/': 1/"
"node": true, "node": true,
"es6": true "es6": true
}, },
"ignorePatterns": [
"jsPDF.min.js",
"SlateEditor/",
"assets"
],
"rules": { "rules": {
"max-len": 0, "max-len": 0,
/*[1, 160, 4],*/ /*[1, 160, 4],*/
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
"steemd_connection_server": "SDC_SERVER_STEEMD_URL", "steemd_connection_server": "SDC_SERVER_STEEMD_URL",
"steemd_use_appbase": "SDC_USE_APPBASE", "steemd_use_appbase": "SDC_USE_APPBASE",
"chain_id": "SDC_CHAIN_ID", "chain_id": "SDC_CHAIN_ID",
"alternative_api_endpoints": "SDC_ALT_API_ENDPOINTS",
"address_prefix": "SDC_ADDRESS_PREFIX", "address_prefix": "SDC_ADDRESS_PREFIX",
"conveyor_posting_wif": "CONVEYOR_POSTING_WIF", "conveyor_posting_wif": "CONVEYOR_POSTING_WIF",
"conveyor_username": "CONVEYOR_USERNAME", "conveyor_username": "CONVEYOR_USERNAME",
...@@ -47,5 +48,5 @@ ...@@ -47,5 +48,5 @@
"steem_market_token": "STEEM_MARKET_TOKEN", "steem_market_token": "STEEM_MARKET_TOKEN",
"cookie_consent_enabled": "SDC_ENABLE_COOKIE_CONSENT", "cookie_consent_enabled": "SDC_ENABLE_COOKIE_CONSENT",
"cookie_consent_api_key": "SDC_COOKIE_CONSENT_KEY", "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"
} }
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
"steemd_connection_server": "https://api.hive.blog", "steemd_connection_server": "https://api.hive.blog",
"steemd_use_appbase": false, "steemd_use_appbase": false,
"chain_id": "0000000000000000000000000000000000000000000000000000000000000000", "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, "failover_threshold": 3,
"address_prefix": "STM", "address_prefix": "STM",
"conveyor_posting_wif": false, "conveyor_posting_wif": false,
......
...@@ -29,7 +29,8 @@ services: ...@@ -29,7 +29,8 @@ services:
SDC_SITE_DOMAIN: hive.blog SDC_SITE_DOMAIN: hive.blog
SDC_IMAGE_PROXY_PREFIX: https://images.hive.blog/ SDC_IMAGE_PROXY_PREFIX: https://images.hive.blog/
SDC_UPLOAD_IMAGE_URL: 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 WALLET_URL: https://wallet.hive.blog
networks: networks:
- reverse-proxy - reverse-proxy
......
...@@ -83,24 +83,23 @@ function runApp(initial_state) { ...@@ -83,24 +83,23 @@ function runApp(initial_state) {
cmd(CMD_LOG_O); 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({ steem.api.setOptions({
url: url: currentApiEndpoint,
localStorage.getItem('user_preferred_api_endpoint') === null
? config.steemd_connection_client
: localStorage.getItem('user_preferred_api_endpoint'),
retry: true, retry: true,
useAppbaseApi: !!config.steemd_use_appbase, useAppbaseApi: !!config.steemd_use_appbase,
alternative_api_endpoints: config.alternative_api_endpoints, alternative_api_endpoints: alternativeApiEndpoints,
failover_threshold: config.failover_threshold, failover_threshold: config.failover_threshold,
}); });
steem.config.set('address_prefix', config.address_prefix); steem.config.set('address_prefix', config.address_prefix);
steem.config.set('chain_id', config.chain_id); 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; window.$STM_Config = config;
plugins(config); plugins(config);
if (initial_state.offchain.serverBusy) { if (initial_state.offchain.serverBusy) {
......
...@@ -233,22 +233,38 @@ class Settings extends React.Component { ...@@ -233,22 +233,38 @@ class Settings extends React.Component {
this.props.setUserPreferences(userPreferences); 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 = () => { generateAPIEndpointOptions = () => {
let endpoints = api.config.get('alternative_api_endpoints'); const 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');
if (endpoints === null || endpoints === undefined) { if (endpoints === null || endpoints === undefined) {
return null; return null;
} }
let entries = [];
for (var endpoint of endpoints) { const preferred_api_endpoint = this.getPreferredApiEndpoint();
if (endpoint === preferred_api_endpoint) continue; //this one is always present even if the api config call fails const entries = [];
let entry = <option value={endpoint}>{endpoint}</option>; for (let ei = 0; ei < endpoints.length; ei += 1) {
entries.push(entry); 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; return entries;
}; };
...@@ -292,13 +308,7 @@ class Settings extends React.Component { ...@@ -292,13 +308,7 @@ class Settings extends React.Component {
progress, progress,
} = this.state; } = this.state;
let preferred_api_endpoint = 'https://api.hive.blog'; const preferred_api_endpoint = this.getPreferredApiEndpoint();
if (typeof window !== 'undefined') {
preferred_api_endpoint =
localStorage.getItem('user_preferred_api_endpoint') === null
? 'https://api.hive.blog'
: localStorage.getItem('user_preferred_api_endpoint');
}
return ( return (
<div className="Settings"> <div className="Settings">
......
...@@ -16,6 +16,10 @@ require('module').Module._initPaths(); ...@@ -16,6 +16,10 @@ require('module').Module._initPaths();
// Load Intl polyfill // Load Intl polyfill
// require('utils/intl-polyfill')(require('./config/init').locales); // require('utils/intl-polyfill')(require('./config/init').locales);
const alternativeApiEndpoints = config
.get('alternative_api_endpoints')
.split(' ');
global.$STM_Config = { global.$STM_Config = {
fb_app: config.get('facebook_app_id'), fb_app: config.get('facebook_app_id'),
steemd_connection_client: config.get('steemd_connection_client'), steemd_connection_client: config.get('steemd_connection_client'),
...@@ -31,7 +35,7 @@ global.$STM_Config = { ...@@ -31,7 +35,7 @@ global.$STM_Config = {
google_analytics_id: config.get('google_analytics_id'), google_analytics_id: config.get('google_analytics_id'),
wallet_url: config.get('wallet_url'), wallet_url: config.get('wallet_url'),
failover_threshold: config.get('failover_threshold'), failover_threshold: config.get('failover_threshold'),
alternative_api_endpoints: config.get('alternative_api_endpoints'), alternative_api_endpoints: alternativeApiEndpoints,
}; };
const WebpackIsomorphicTools = require('webpack-isomorphic-tools'); const WebpackIsomorphicTools = require('webpack-isomorphic-tools');
...@@ -52,16 +56,11 @@ global.webpackIsomorphicTools.server(ROOT, () => { ...@@ -52,16 +56,11 @@ global.webpackIsomorphicTools.server(ROOT, () => {
randomize: true, randomize: true,
}, },
useAppbaseApi: !!config.steemd_use_appbase, useAppbaseApi: !!config.steemd_use_appbase,
alternative_api_endpoints: config.get('alternative_api_endpoints'), alternative_api_endpoints: alternativeApiEndpoints,
failover_threshold: config.get('failover_threshold'), failover_threshold: config.get('failover_threshold'),
}); });
steem.config.set('address_prefix', config.get('address_prefix')); steem.config.set('address_prefix', config.get('address_prefix'));
steem.config.set('chain_id', config.get('chain_id')); 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; // const CliWalletClient = require('shared/api_client/CliWalletClient').default;
// if (process.env.NODE_ENV === 'production') connect_promises.push(CliWalletClient.instance().connect_promise()); // if (process.env.NODE_ENV === 'production') connect_promises.push(CliWalletClient.instance().connect_promise());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment