mirror of
https://github.com/KevinMidboe/planetposen-frontend.git
synced 2026-02-15 11:49:22 +00:00
Use hooks to check env and rewrite API call url if localhost
This commit is contained in:
@@ -1,19 +1,12 @@
|
||||
import { dev } from '$app/environment';
|
||||
import { env } from '$env/dynamic/private';
|
||||
import generateProductJsonLd from '$lib/jsonld/product';
|
||||
import type { IProductResponse } from '$lib/interfaces/ApiResponse';
|
||||
import type { IProductDTO } from '$lib/interfaces/ApiResponse';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ fetch, params }) => {
|
||||
const { id } = params;
|
||||
|
||||
let url = `/api/product/${id}`;
|
||||
if (dev || env.API_HOST) {
|
||||
url = (env.API_HOST || 'http://localhost:30010').concat(url);
|
||||
}
|
||||
|
||||
const res = await fetch(url);
|
||||
const productResponse: IProductResponse = await res.json();
|
||||
const res = await fetch(`/api/product/${id}`);
|
||||
const productResponse: IProductDTO = await res.json();
|
||||
const jsonld = generateProductJsonLd(productResponse?.product);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user