Merge pull request #291 from lbryio/connection-string-override

Connection string override
This commit is contained in:
Jeremy Kauffman 2020-03-20 10:39:26 -04:00 committed by GitHub
commit 7517aceb07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 2 deletions

5
dist/bundle.es.js vendored
View file

@ -884,6 +884,8 @@ const Lbry = {
isConnected: false, isConnected: false,
connectPromise: null, connectPromise: null,
daemonConnectionString: 'http://localhost:5279', daemonConnectionString: 'http://localhost:5279',
alternateConnectionString: '',
methodsUsingAlternateConnectionString: [],
apiRequestHeaders: { 'Content-Type': 'application/json-rpc' }, apiRequestHeaders: { 'Content-Type': 'application/json-rpc' },
// Allow overriding daemon connection string (e.g. to `/api/proxy` for lbryweb) // Allow overriding daemon connection string (e.g. to `/api/proxy` for lbryweb)
@ -1052,7 +1054,8 @@ function apiCall(method, params, resolve, reject) {
}) })
}; };
return fetch(Lbry.daemonConnectionString + '?m=' + method, options).then(checkAndParse).then(response => { const connectionString = Lbry.methodsUsingAlternateConnectionString.includes(method) ? Lbry.alternateConnectionString : Lbry.daemonConnectionString;
return fetch(connectionString + '?m=' + method, options).then(checkAndParse).then(response => {
const error = response.error || response.result && response.result.error; const error = response.error || response.result && response.result.error;
if (error) { if (error) {

View file

@ -221,6 +221,8 @@ declare type LbryTypes = {
connectPromise: ?Promise<any>, connectPromise: ?Promise<any>,
connect: () => void, connect: () => void,
daemonConnectionString: string, daemonConnectionString: string,
alternateConnectionString: string,
methodsUsingAlternateConnectionString: Array<string>,
apiRequestHeaders: { [key: string]: string }, apiRequestHeaders: { [key: string]: string },
setDaemonConnectionString: string => void, setDaemonConnectionString: string => void,
setApiHeader: (string, string) => void, setApiHeader: (string, string) => void,

2
flow-typed/Lbry.js vendored
View file

@ -221,6 +221,8 @@ declare type LbryTypes = {
connectPromise: ?Promise<any>, connectPromise: ?Promise<any>,
connect: () => void, connect: () => void,
daemonConnectionString: string, daemonConnectionString: string,
alternateConnectionString: string,
methodsUsingAlternateConnectionString: Array<string>,
apiRequestHeaders: { [key: string]: string }, apiRequestHeaders: { [key: string]: string },
setDaemonConnectionString: string => void, setDaemonConnectionString: string => void,
setApiHeader: (string, string) => void, setApiHeader: (string, string) => void,

View file

@ -11,6 +11,8 @@ const Lbry: LbryTypes = {
isConnected: false, isConnected: false,
connectPromise: null, connectPromise: null,
daemonConnectionString: 'http://localhost:5279', daemonConnectionString: 'http://localhost:5279',
alternateConnectionString: '',
methodsUsingAlternateConnectionString: [],
apiRequestHeaders: { 'Content-Type': 'application/json-rpc' }, apiRequestHeaders: { 'Content-Type': 'application/json-rpc' },
// Allow overriding daemon connection string (e.g. to `/api/proxy` for lbryweb) // Allow overriding daemon connection string (e.g. to `/api/proxy` for lbryweb)
@ -191,7 +193,10 @@ export function apiCall(method: string, params: ?{}, resolve: Function, reject:
}), }),
}; };
return fetch(Lbry.daemonConnectionString + '?m=' + method, options) const connectionString = Lbry.methodsUsingAlternateConnectionString.includes(method)
? Lbry.alternateConnectionString
: Lbry.daemonConnectionString;
return fetch(connectionString + '?m=' + method, options)
.then(checkAndParse) .then(checkAndParse)
.then(response => { .then(response => {
const error = response.error || (response.result && response.result.error); const error = response.error || (response.result && response.result.error);