Skip to content

Commit 135e899

Browse files
authored
Merge pull request #72 from kaleido-io/baseUrlOptions
baseURL options
2 parents 089f39b + 2485e06 commit 135e899

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

lib/http.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,26 @@ export default class HttpBase {
5757
this.options = this.setDefaults(options);
5858
this.rootHttp = axios.create({
5959
...options.requestConfig,
60-
baseURL: `${options.host}/api/v1`,
60+
baseURL: options.baseURL,
6161
});
6262
this.http = axios.create({
6363
...options.requestConfig,
64-
baseURL: `${options.host}/api/v1/namespaces/${this.options.namespace}`,
64+
baseURL: options.namespaceBaseURL,
6565
});
6666
}
6767

6868
private setDefaults(options: FireFlyOptionsInput): FireFlyOptions {
69+
const baseURLSet = (options.baseURL ?? '') !== '' && (options.namespaceBaseURL ?? '' !== '');
70+
if (!baseURLSet && (options.host ?? '') === '') {
71+
throw new Error('Invalid options. Option host, or baseURL and namespaceBaseURL must be set.');
72+
}
73+
6974
return {
7075
...options,
76+
baseURL: baseURLSet ? options.baseURL : `${options.host}/api/v1`,
77+
namespaceBaseURL: baseURLSet
78+
? options.namespaceBaseURL
79+
: `${options.host}/api/v1/namespaces/${options.namespace}`,
7180
namespace: options.namespace ?? 'default',
7281
websocket: {
7382
...options.websocket,

lib/interfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export interface FireFlyOptionsInput {
4242
namespace?: string;
4343
username?: string;
4444
password?: string;
45+
baseURL?: string;
46+
namespaceBaseURL?: string;
4547
websocket?: {
4648
host?: string;
4749
reconnectDelay?: number;

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hyperledger/firefly-sdk",
3-
"version": "1.2.10",
3+
"version": "1.2.11",
44
"description": "Client SDK for Hyperledger FireFly",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -45,4 +45,4 @@
4545
"form-data": "^4.0.0",
4646
"ws": "^8.5.0"
4747
}
48-
}
48+
}

0 commit comments

Comments
 (0)