Connection string override #291
4 changed files with 14 additions and 2 deletions
5
dist/bundle.es.js
vendored
5
dist/bundle.es.js
vendored
|
@ -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) {
|
||||||
|
|
2
dist/flow-typed/Lbry.js
vendored
2
dist/flow-typed/Lbry.js
vendored
|
@ -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
2
flow-typed/Lbry.js
vendored
|
@ -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,
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue