Refactor fetchJson function to use relative paths in the browser and avoid mixed content issues

This commit is contained in:
Nils-Johan Gynther
2026-04-09 23:58:19 +02:00
parent fd8480197c
commit 32e643f6ab
+6 -1
View File
@@ -2,7 +2,12 @@ const API_BASE =
process.env.NEXT_PUBLIC_API_URL_INTERNAL || 'http://recipe-api:8080';
export async function fetchJson<T>(path: string, init?: RequestInit): Promise<T> {
const res = await fetch(`${API_BASE}${path}`, {
// Använd alltid relativ path i webbläsaren för att undvika mixed content
const url = typeof window === 'undefined'
? (path.startsWith('http') ? path : `${API_BASE}${path}`)
: path;
const res = await fetch(url, {
...init,
cache: 'no-store',
headers: {