Skip to content

Commit

Permalink
fix: use absolute urls for fetches in all fetch calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Kühnlein committed Feb 17, 2024
1 parent 7d995de commit aecef8a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
12 changes: 8 additions & 4 deletions app/src/app/[locale]/importer/[id]/mapping/SelectMappings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
});
Expand Down
7 changes: 5 additions & 2 deletions app/src/app/[locale]/importer/[id]/validate/Validation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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",
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/components/hooks/useGetImporter.tsx
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion app/src/components/hooks/useGetMappingRecommendations.tsx
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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()),
{
Expand Down

0 comments on commit aecef8a

Please sign in to comment.