Skip to content
This repository was archived by the owner on Dec 10, 2021. It is now read-only.

Commit 03883ef

Browse files
committed
Add const DEFAULT_BASE_URL
1 parent 8231529 commit 03883ef

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

packages/superset-ui-connection/src/SupersetClientClass.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
RequestConfig,
3232
ParseMethod,
3333
} from './types';
34-
import { DEFAULT_FETCH_RETRY_OPTIONS } from './constants';
34+
import { DEFAULT_FETCH_RETRY_OPTIONS, DEFAULT_BASE_URL } from './constants';
3535

3636
export default class SupersetClientClass {
3737
credentials: Credentials;
@@ -46,7 +46,7 @@ export default class SupersetClientClass {
4646
timeout: ClientTimeout;
4747

4848
constructor({
49-
baseUrl = 'http://localhost',
49+
baseUrl = DEFAULT_BASE_URL,
5050
host,
5151
protocol,
5252
headers = {},
@@ -60,7 +60,7 @@ export default class SupersetClientClass {
6060
host || protocol ? `${protocol || 'https:'}//${host || 'localhost'}` : baseUrl,
6161
// baseUrl for API could also be relative, so we provide current location.href
6262
// as the base of baseUrl
63-
window.location.href || 'http://localhost',
63+
window.location.href || DEFAULT_BASE_URL,
6464
);
6565
this.baseUrl = url.href.replace(/\/+$/, ''); // always strip trailing slash
6666
this.host = url.host;

packages/superset-ui-connection/src/callApi/callApi.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import 'whatwg-fetch';
22
import fetchRetry from 'fetch-retry';
33
import { CallApi, Payload, JsonValue } from '../types';
4-
import { CACHE_AVAILABLE, CACHE_KEY, HTTP_STATUS_NOT_MODIFIED, HTTP_STATUS_OK } from '../constants';
4+
import {
5+
CACHE_AVAILABLE,
6+
CACHE_KEY,
7+
HTTP_STATUS_NOT_MODIFIED,
8+
HTTP_STATUS_OK,
9+
DEFAULT_BASE_URL,
10+
} from '../constants';
511

612
function tryParsePayload(payload: Payload) {
713
try {
@@ -16,7 +22,7 @@ function tryParsePayload(payload: Payload) {
1622
*/
1723
function getFullUrl(partialUrl: string, params: CallApi['searchParams']) {
1824
if (params) {
19-
const url = new URL(partialUrl, window.location.href);
25+
const url = new URL(partialUrl, window.location.href || DEFAULT_BASE_URL);
2026
const search = params instanceof URLSearchParams ? params : new URLSearchParams(params);
2127
// will completely override any existing search params
2228
url.search = search.toString();

packages/superset-ui-connection/src/constants.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { FetchRetryOptions } from './types';
22

3+
export const DEFAULT_BASE_URL = 'http://localhost';
4+
35
// HTTP status codes
46
export const HTTP_STATUS_OK = 200;
57
export const HTTP_STATUS_NOT_MODIFIED = 304;

0 commit comments

Comments
 (0)