Connection string override #291

Merged
akinwale merged 2 commits from connection-string-override into master 2020-03-20 15:39:27 +01:00
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,
connectPromise: null,
daemonConnectionString: 'http://localhost:5279',
alternateConnectionString: '',
methodsUsingAlternateConnectionString: [],
apiRequestHeaders: { 'Content-Type': 'application/json-rpc' },
// 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;
if (error) {

View file

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

2
flow-typed/Lbry.js vendored
View file

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

View file

@ -11,6 +11,8 @@ const Lbry: LbryTypes = {
isConnected: false,
connectPromise: null,
daemonConnectionString: 'http://localhost:5279',
alternateConnectionString: '',
methodsUsingAlternateConnectionString: [],
apiRequestHeaders: { 'Content-Type': 'application/json-rpc' },
// 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(response => {
const error = response.error || (response.result && response.result.error);