fix(web): api context should pass it's current hostname into API URL selector

This commit is contained in:
41666 2021-03-13 05:21:09 -05:00
parent eb2537ae35
commit 2b467b8452
2 changed files with 17 additions and 17 deletions

View file

@ -8,7 +8,7 @@ type ApiContextData = {
}; };
export const ApiContext = React.createContext<ApiContextData>({ export const ApiContext = React.createContext<ApiContextData>({
apiUrl: getDefaultApiUrl(), apiUrl: getDefaultApiUrl(window.location.hostname),
setApiUrl: () => {}, setApiUrl: () => {},
fetch: async () => { fetch: async () => {
return new Response(); return new Response();
@ -18,7 +18,9 @@ export const ApiContext = React.createContext<ApiContextData>({
export const useApiContext = () => React.useContext(ApiContext); export const useApiContext = () => React.useContext(ApiContext);
export const ApiContextProvider = (props: { children: React.ReactNode }) => { export const ApiContextProvider = (props: { children: React.ReactNode }) => {
const [apiUrl, setApiUrl] = React.useState(getDefaultApiUrl()); const [apiUrl, setApiUrl] = React.useState(
getDefaultApiUrl(window.location.hostname)
);
const apiContextData: ApiContextData = { const apiContextData: ApiContextData = {
apiUrl, apiUrl,

View file

@ -1,7 +1,6 @@
import * as memoizeOne from 'memoize-one'; import * as memoizeOne from 'memoize-one';
export const getDefaultApiUrl = memoizeOne.default( export const getDefaultApiUrl = memoizeOne.default((host: string) => {
(host: string = window.location.hostname) => {
if (/^roleypoly.com$/.test(host)) { if (/^roleypoly.com$/.test(host)) {
return 'https://api-prod.roleypoly.com'; return 'https://api-prod.roleypoly.com';
} else if ( } else if (
@ -14,5 +13,4 @@ export const getDefaultApiUrl = memoizeOne.default(
} else { } else {
return 'https://api-prod.roleypoly.com'; return 'https://api-prod.roleypoly.com';
} }
} });
);