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

Commit

Permalink
Add const DEFAULT_BASE_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmud committed Jul 3, 2020
1 parent 49eb800 commit e25d9f4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/superset-ui-connection/src/SupersetClientClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
RequestConfig,
ParseMethod,
} from './types';
import { DEFAULT_FETCH_RETRY_OPTIONS } from './constants';
import { DEFAULT_FETCH_RETRY_OPTIONS, DEFAULT_BASE_URL } from './constants';

export default class SupersetClientClass {
credentials: Credentials;
Expand All @@ -46,7 +46,7 @@ export default class SupersetClientClass {
timeout: ClientTimeout;

constructor({
baseUrl = 'http://localhost',
baseUrl = DEFAULT_BASE_URL,
host,
protocol,
headers = {},
Expand All @@ -60,7 +60,7 @@ export default class SupersetClientClass {
host || protocol ? `${protocol || 'https:'}//${host || 'localhost'}` : baseUrl,
// baseUrl for API could also be relative, so we provide current location.href
// as the base of baseUrl
window.location.href || 'http://localhost',
window.location.href || DEFAULT_BASE_URL,
);
this.baseUrl = url.href.replace(/\/+$/, ''); // always strip trailing slash
this.host = url.host;
Expand Down
10 changes: 8 additions & 2 deletions packages/superset-ui-connection/src/callApi/callApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import 'whatwg-fetch';
import fetchRetry from 'fetch-retry';
import { CallApi, Payload, JsonValue } from '../types';
import { CACHE_AVAILABLE, CACHE_KEY, HTTP_STATUS_NOT_MODIFIED, HTTP_STATUS_OK } from '../constants';
import {
CACHE_AVAILABLE,
CACHE_KEY,
HTTP_STATUS_NOT_MODIFIED,
HTTP_STATUS_OK,
DEFAULT_BASE_URL,
} from '../constants';

function tryParsePayload(payload: Payload) {
try {
Expand All @@ -16,7 +22,7 @@ function tryParsePayload(payload: Payload) {
*/
function getFullUrl(partialUrl: string, params: CallApi['searchParams']) {
if (params) {
const url = new URL(partialUrl, window.location.href);
const url = new URL(partialUrl, window.location.href || DEFAULT_BASE_URL);
const search = params instanceof URLSearchParams ? params : new URLSearchParams(params);
// will completely override any existing search params
url.search = search.toString();
Expand Down
2 changes: 2 additions & 0 deletions packages/superset-ui-connection/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { FetchRetryOptions } from './types';

export const DEFAULT_BASE_URL = 'http://localhost';

// HTTP status codes
export const HTTP_STATUS_OK = 200;
export const HTTP_STATUS_NOT_MODIFIED = 304;
Expand Down

0 comments on commit e25d9f4

Please sign in to comment.