Skip to content

Commit 2485e06

Browse files
committed
check URLs and host options
Signed-off-by: Matthew Clarke <[email protected]>
1 parent 974a7d5 commit 2485e06

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/http.ts

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

6968
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+
7074
return {
7175
...options,
76+
baseURL: baseURLSet ? options.baseURL : `${options.host}/api/v1`,
77+
namespaceBaseURL: baseURLSet
78+
? options.namespaceBaseURL
79+
: `${options.host}/api/v1/namespaces/${options.namespace}`,
7280
namespace: options.namespace ?? 'default',
7381
websocket: {
7482
...options.websocket,

lib/interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface FireFlyOptionsInput {
4242
namespace?: string;
4343
username?: string;
4444
password?: string;
45-
baseUrl?: string;
45+
baseURL?: string;
4646
namespaceBaseURL?: string;
4747
websocket?: {
4848
host?: string;

0 commit comments

Comments
 (0)