Allow passing of endpoint via url (#1382)

* Allow passing of endpoint via url

* Add latest query-string package
This commit is contained in:
Jaco Greeff 2019-07-17 13:46:00 +02:00 committed by GitHub
parent be084250f0
commit 083ee86226
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 4 deletions

View File

@ -15,6 +15,7 @@
"@babel/runtime": "^7.5.4",
"@polkadot/ui-app": "^0.34.0-beta.70",
"@polkadot/ui-assets": "^0.42.0-beta.11",
"@polkadot/ui-signer": "^0.34.0-beta.70"
"@polkadot/ui-signer": "^0.34.0-beta.70",
"query-string": "^6.8.1"
}
}

View File

@ -8,6 +8,7 @@ import settings from '@polkadot/ui-settings';
import '@polkadot/ui-app/i18n';
import '@polkadot/ui-app/styles';
import queryString from 'query-string';
import React, { Suspense } from 'react';
import ReactDOM from 'react-dom';
import { HashRouter } from 'react-router-dom';
@ -22,13 +23,22 @@ import Apps from './Apps';
const rootId = 'root';
const rootElement = document.getElementById(rootId);
const url = process.env.WS_URL || settings.apiUrl || undefined;
// we split here so that both these forms are allowed
// - http://localhost:3000/?rpc=wss://substrate-rpc.parity.io/#/explorer
// - http://localhost:3000/#/explorer?rpc=wss://substrate-rpc.parity.io
const urlOptions = queryString.parse(location.href.split('?')[1]);
const wsEndpoint = urlOptions.rpc || process.env.WS_URL || settings.apiUrl || undefined;
if (Array.isArray(wsEndpoint)) {
throw new Error('Invalid WS endpoint specified');
}
if (!rootElement) {
throw new Error(`Unable to find element with id '${rootId}'`);
}
console.log('Web socket url=', url);
console.log('WS endpoint=', wsEndpoint);
try {
const types = store.get('types') || {};
@ -54,7 +64,7 @@ ReactDOM.render(
<Api
queueExtrinsic={queueExtrinsic}
queueSetTxStatus={queueSetTxStatus}
url={url}
url={wsEndpoint}
>
<HashRouter>
<ThemeProvider theme={theme}>

View File

@ -12268,6 +12268,15 @@ query-string@^5.0.1:
object-assign "^4.1.0"
strict-uri-encode "^1.0.0"
query-string@^6.8.1:
version "6.8.1"
resolved "https://registry.yarnpkg.com/query-string/-/query-string-6.8.1.tgz#62c54a7ef37d01b538c8fd56f95740c81d438a26"
integrity sha512-g6y0Lbq10a5pPQpjlFuojfMfV1Pd2Jw9h75ypiYPPia3Gcq2rgkKiIwbkS6JxH7c5f5u/B/sB+d13PU+g1eu4Q==
dependencies:
decode-uri-component "^0.2.0"
split-on-first "^1.0.0"
strict-uri-encode "^2.0.0"
querystring-es3@^0.2.0, querystring-es3@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73"
@ -13639,6 +13648,11 @@ spdy@^4.0.0:
select-hose "^2.0.0"
spdy-transport "^3.0.0"
split-on-first@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/split-on-first/-/split-on-first-1.1.0.tgz#f610afeee3b12bce1d0c30425e76398b78249a5f"
integrity sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw==
split-string@^3.0.1, split-string@^3.0.2:
version "3.1.0"
resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2"
@ -13779,6 +13793,11 @@ strict-uri-encode@^1.0.0:
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz#279b225df1d582b1f54e65addd4352e18faa0713"
integrity sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=
strict-uri-encode@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546"
integrity sha1-ucczDHBChi9rFC3CdLvMWGbONUY=
string-length@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/string-length/-/string-length-2.0.0.tgz#d40dbb686a3ace960c1cffca562bf2c45f8363ed"