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>({
|
||||
apiUrl: getDefaultApiUrl(),
|
||||
apiUrl: getDefaultApiUrl(window.location.hostname),
|
||||
setApiUrl: () => {},
|
||||
fetch: async () => {
|
||||
return new Response();
|
||||
|
@ -18,7 +18,9 @@ export const ApiContext = React.createContext<ApiContextData>({
|
|||
export const useApiContext = () => React.useContext(ApiContext);
|
||||
|
||||
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 = {
|
||||
apiUrl,
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
import * as memoizeOne from 'memoize-one';
|
||||
|
||||
export const getDefaultApiUrl = memoizeOne.default(
|
||||
(host: string = window.location.hostname) => {
|
||||
if (/^roleypoly.com$/.test(host)) {
|
||||
return 'https://api-prod.roleypoly.com';
|
||||
} else if (
|
||||
/roleypoly\.pages\.dev$/.test(host) ||
|
||||
/^stage.roleypoly.com$/.test(host)
|
||||
) {
|
||||
return 'https://api-stage.roleypoly.com';
|
||||
} else if (/\blocalhost|127\.0\.0\.1\b/.test(host)) {
|
||||
return 'http://localhost:6609';
|
||||
} else {
|
||||
return 'https://api-prod.roleypoly.com';
|
||||
}
|
||||
export const getDefaultApiUrl = memoizeOne.default((host: string) => {
|
||||
if (/^roleypoly.com$/.test(host)) {
|
||||
return 'https://api-prod.roleypoly.com';
|
||||
} else if (
|
||||
/roleypoly\.pages\.dev$/.test(host) ||
|
||||
/^stage.roleypoly.com$/.test(host)
|
||||
) {
|
||||
return 'https://api-stage.roleypoly.com';
|
||||
} else if (/\blocalhost|127\.0\.0\.1\b/.test(host)) {
|
||||
return 'http://localhost:6609';
|
||||
} else {
|
||||
return 'https://api-prod.roleypoly.com';
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue