|
@@ -2,19 +2,14 @@ import { useEffect, useState } from 'react';
|
|
|
import { ApolloClient } from '@apollo/client';
|
|
|
import { createApolloClient } from '../core/apollo/client';
|
|
|
import { useSystemStore } from '../state/systemStore';
|
|
|
-import useSWR, { Fetcher } from 'swr';
|
|
|
-import { getUrl } from '../core/helpers/url-helpers';
|
|
|
|
|
|
interface IReturnProps {
|
|
|
client?: ApolloClient<unknown>;
|
|
|
isLoadingComplete?: boolean;
|
|
|
}
|
|
|
|
|
|
-const fetcher: Fetcher<{ ip: string; domain: string; port: string }, string> = (...args) => fetch(...args).then((res) => res.json());
|
|
|
-
|
|
|
export default function useCachedResources(): IReturnProps {
|
|
|
- const { data } = useSWR(getUrl('api/getenv'), fetcher);
|
|
|
- const { baseUrl, setBaseUrl, setInternalIp, setDomain } = useSystemStore();
|
|
|
+ const { baseUrl, setBaseUrl } = useSystemStore();
|
|
|
const [isLoadingComplete, setLoadingComplete] = useState(false);
|
|
|
const [client, setClient] = useState<ApolloClient<unknown>>();
|
|
|
|
|
@@ -32,23 +27,15 @@ export default function useCachedResources(): IReturnProps {
|
|
|
}
|
|
|
|
|
|
useEffect(() => {
|
|
|
- const { ip, domain, port } = data || {};
|
|
|
-
|
|
|
- if (ip && !baseUrl) {
|
|
|
- setInternalIp(ip);
|
|
|
- setDomain(domain);
|
|
|
-
|
|
|
- if (!domain || domain === 'tipi.localhost') {
|
|
|
- if (port === '80') {
|
|
|
- setBaseUrl(`http://${ip}/api`);
|
|
|
- } else {
|
|
|
- setBaseUrl(`http://${ip}:${port}/api`);
|
|
|
- }
|
|
|
- } else {
|
|
|
- setBaseUrl(`https://${domain}/api`);
|
|
|
- }
|
|
|
+ const hostname = window.location.hostname;
|
|
|
+ const port = window.location.port;
|
|
|
+
|
|
|
+ if (!port) {
|
|
|
+ setBaseUrl(`http://${hostname}/api`);
|
|
|
+ } else {
|
|
|
+ setBaseUrl(`http://${hostname}:${port}/api`);
|
|
|
}
|
|
|
- }, [baseUrl, setBaseUrl, setInternalIp, setDomain, data]);
|
|
|
+ }, [setBaseUrl]);
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (baseUrl) {
|