mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-24 19:39:11 +00:00
fix(web): api context should pass it's current hostname into API URL selector
This commit is contained in:
parent
eb2537ae35
commit
2b467b8452
2 changed files with 17 additions and 17 deletions
|
@ -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,
|
||||||
|
|
|
@ -1,18 +1,16 @@
|
||||||
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 (
|
/roleypoly\.pages\.dev$/.test(host) ||
|
||||||
/roleypoly\.pages\.dev$/.test(host) ||
|
/^stage.roleypoly.com$/.test(host)
|
||||||
/^stage.roleypoly.com$/.test(host)
|
) {
|
||||||
) {
|
return 'https://api-stage.roleypoly.com';
|
||||||
return 'https://api-stage.roleypoly.com';
|
} else if (/\blocalhost|127\.0\.0\.1\b/.test(host)) {
|
||||||
} else if (/\blocalhost|127\.0\.0\.1\b/.test(host)) {
|
return 'http://localhost:6609';
|
||||||
return 'http://localhost:6609';
|
} else {
|
||||||
} else {
|
return 'https://api-prod.roleypoly.com';
|
||||||
return 'https://api-prod.roleypoly.com';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue