From aecef8af1fcca3b30e52d6d4745afcdfd479c450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=BChnlein?= Date: Sat, 17 Feb 2024 14:47:16 +0100 Subject: [PATCH] fix: use absolute urls for fetches in all fetch calls --- .../importer/[id]/mapping/SelectMappings.tsx | 12 ++++++++---- .../importer/[id]/select-file/SelectFileUploader.tsx | 3 ++- .../[locale]/importer/[id]/validate/Validation.tsx | 7 +++++-- app/src/components/hooks/useGetImporter.tsx | 3 ++- .../hooks/useGetMappingRecommendations.tsx | 3 ++- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/src/app/[locale]/importer/[id]/mapping/SelectMappings.tsx b/app/src/app/[locale]/importer/[id]/mapping/SelectMappings.tsx index 49087c0..a5baed5 100644 --- a/app/src/app/[locale]/importer/[id]/mapping/SelectMappings.tsx +++ b/app/src/app/[locale]/importer/[id]/mapping/SelectMappings.tsx @@ -27,6 +27,7 @@ import { ChevronRightCircleIcon } from "lucide-react"; import { useRouter } from "next/navigation"; import { fetchWithAuth } from "@/lib/frontendFetch"; +import { getHost } from "@/lib/utils"; import React from "react"; import { useTranslation } from "react-i18next"; import { getPageForState } from "../redirectUtil"; @@ -102,10 +103,13 @@ const SelectMappings = ({ } setIsSavingMapping(true); try { - await fetchWithAuth(`/api/importer/${importer.importerId}/mappings`, { - method: "PUT", - body: JSON.stringify(currentMappings), - }); + await fetchWithAuth( + `${getHost()}/api/importer/${importer.importerId}/mappings`, + { + method: "PUT", + body: JSON.stringify(currentMappings), + } + ); setEnablePolling(true); } catch (err) { console.error(err); diff --git a/app/src/app/[locale]/importer/[id]/select-file/SelectFileUploader.tsx b/app/src/app/[locale]/importer/[id]/select-file/SelectFileUploader.tsx index bd1a51f..6e7658c 100644 --- a/app/src/app/[locale]/importer/[id]/select-file/SelectFileUploader.tsx +++ b/app/src/app/[locale]/importer/[id]/select-file/SelectFileUploader.tsx @@ -4,6 +4,7 @@ import { useGetImporter } from "@/components/hooks/useGetImporter"; import { LoadingSpinner } from "@/components/ui/loadingSpinner"; import { useToast } from "@/components/ui/use-toast"; import { fetchWithAuth } from "@/lib/frontendFetch"; +import { getHost } from "@/lib/utils"; import { useRouter } from "next/navigation"; import React from "react"; import { useTranslation } from "react-i18next"; @@ -39,7 +40,7 @@ const SelectFileUploader = ({ importerDto: initialImporterDto }: Props) => { const formData = new FormData(); formData.append("file", file); formData.append("importerId", importer.importerId); - await fetchWithAuth("/api/upload", { + await fetchWithAuth(`${getHost()}/api/upload`, { method: "POST", body: formData, }); diff --git a/app/src/app/[locale]/importer/[id]/validate/Validation.tsx b/app/src/app/[locale]/importer/[id]/validate/Validation.tsx index d7779a7..08c7e6f 100644 --- a/app/src/app/[locale]/importer/[id]/validate/Validation.tsx +++ b/app/src/app/[locale]/importer/[id]/validate/Validation.tsx @@ -8,6 +8,7 @@ import { Button } from "@/components/ui/button"; import { LoadingSpinner } from "@/components/ui/loadingSpinner"; import { useToast } from "@/components/ui/use-toast"; import { fetchWithAuth } from "@/lib/frontendFetch"; +import { getHost } from "@/lib/utils"; import { enableMapSet, produce } from "immer"; import { sum } from "lodash"; import { ChevronRightCircleIcon } from "lucide-react"; @@ -154,7 +155,7 @@ const Validation = ({ ); try { const res = await fetchWithAuth( - `/api/importer/${initialImporterDto.importerId}/records`, + `${getHost()}/api/importer/${initialImporterDto.importerId}/records`, { method: "PATCH", body: JSON.stringify({ @@ -191,7 +192,9 @@ const Validation = ({ setIsStartingImport(true); try { await fetchWithAuth( - `/api/importer/${initialImporterDto.importerId}/start-import`, + `${getHost()}/api/importer/${ + initialImporterDto.importerId + }/start-import`, { method: "POST", } diff --git a/app/src/components/hooks/useGetImporter.tsx b/app/src/components/hooks/useGetImporter.tsx index 6096633..c4f846c 100644 --- a/app/src/components/hooks/useGetImporter.tsx +++ b/app/src/components/hooks/useGetImporter.tsx @@ -1,5 +1,6 @@ import { ImporterDto } from "@/app/api/importer/[slug]/ImporterDto"; import { fetchWithAuth } from "@/lib/frontendFetch"; +import { getHost } from "@/lib/utils"; import useSWR from "swr"; export function useGetImporter( @@ -8,7 +9,7 @@ export function useGetImporter( fallbackData?: ImporterDto ) { const { data, error, isLoading, mutate } = useSWR( - importerId ? [`/api/importer/${importerId}`] : null, + importerId ? [`${getHost()}/api/importer/${importerId}`] : null, ([url]) => fetchWithAuth(url).then((res) => res.json()), { refreshInterval: pollInterval, diff --git a/app/src/components/hooks/useGetMappingRecommendations.tsx b/app/src/components/hooks/useGetMappingRecommendations.tsx index 337444a..1f8d799 100644 --- a/app/src/components/hooks/useGetMappingRecommendations.tsx +++ b/app/src/components/hooks/useGetMappingRecommendations.tsx @@ -1,5 +1,6 @@ import { DataMappingRecommendation } from "@/app/api/importer/[slug]/ImporterDto"; import { fetchWithAuth } from "@/lib/frontendFetch"; +import { getHost } from "@/lib/utils"; import useSWR from "swr"; export function useGetMappingRecommendations( @@ -9,7 +10,7 @@ export function useGetMappingRecommendations( ) { const { data, error, isLoading } = useSWR( importerId - ? [`/api/importer/${importerId}/mappings/recommendations`] + ? [`${getHost()}/api/importer/${importerId}/mappings/recommendations`] : null, ([url]) => fetchWithAuth(url).then((res) => res.json()), {