Skip to content

Commit ebccbf9

Browse files
authored
Make the API URL configurable (loic-sharma#370)
1 parent 60433fe commit ebccbf9

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

src/BaGet.UI/src/DisplayPackage/Dependents.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { config } from '../config';
12
import * as React from 'react';
23

34
interface IDependentsProps {
@@ -29,7 +30,7 @@ class Dependents extends React.Component<IDependentsProps, IDependentsState> {
2930
}
3031

3132
public componentDidMount() {
32-
const url = `/v3/dependents?packageId=${this.props.packageId}`;
33+
const url = `${config.apiUrl}/v3/dependents?packageId=${this.props.packageId}`;
3334

3435
fetch(url, {signal: this.controller.signal}).then(response => {
3536
return response.json();

src/BaGet.UI/src/DisplayPackage/DisplayPackage.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { HtmlRenderer, Parser } from 'commonmark';
2+
import { config } from '../config';
23
import { Icon } from 'office-ui-fabric-react/lib/Icon';
34
import * as React from 'react';
45
import { Link } from 'react-router-dom';
@@ -102,7 +103,7 @@ class DisplayPackage extends React.Component<IDisplayPackageProps, IDisplayPacka
102103
}
103104

104105
public componentDidMount() {
105-
const url = `/v3/registration/${this.id}/index.json`;
106+
const url = `${config.apiUrl}/v3/registration/${this.id}/index.json`;
106107

107108
fetch(url, {signal: this.registrationController.signal}).then(response => {
108109
return response.json();
@@ -158,7 +159,7 @@ class DisplayPackage extends React.Component<IDisplayPackageProps, IDisplayPacka
158159
});
159160

160161
if (currentItem.catalogEntry.hasReadme) {
161-
const readmeUrl = `/v3/package/${this.id}/${currentItem.catalogEntry.version}/readme`;
162+
const readmeUrl = `${config.apiUrl}/v3/package/${this.id}/${currentItem.catalogEntry.version}/readme`;
162163

163164
fetch(readmeUrl, {signal: this.readmeController.signal}).then(response => {
164165
return response.text();

src/BaGet.UI/src/SearchResults.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { config } from './config';
12
import { Icon } from 'office-ui-fabric-react/lib/Icon';
23
import { Checkbox, Dropdown, IDropdownOption, SelectableOptionMenuItemType } from 'office-ui-fabric-react/lib/index';
34
import * as React from 'react';
@@ -252,7 +253,7 @@ class SearchResults extends React.Component<ISearchResultsProps, ISearchResultsS
252253
.map(k => `${k}=${encodeURIComponent(parameters[k])}`)
253254
.join('&');
254255

255-
return `/v3/search?${queryString}`;
256+
return `${config.apiUrl}/v3/search?${queryString}`;
256257
}
257258

258259
private loadDefaultIcon = (e: React.SyntheticEvent<HTMLImageElement>) => {

src/BaGet.UI/src/config.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
let config = {
2+
apiUrl: "__BAGET_PLACEHOLDER_API_URL__"
3+
};
4+
5+
if (config.apiUrl.startsWith("__BAGET_PLACEHOLDER_")) {
6+
config.apiUrl = "";
7+
}
8+
9+
if (config.apiUrl.endsWith('/')) {
10+
config.apiUrl = config.apiUrl.slice(0, -1);
11+
}
12+
13+
export { config };

0 commit comments

Comments
 (0)