Put API prefix in server only file to access process.env

This commit is contained in:
thiloho
2024-08-19 20:33:23 +02:00
parent 488877b2ed
commit 28774dc944
15 changed files with 29 additions and 25 deletions

View File

@@ -1,5 +1,5 @@
import type { Actions, PageServerLoad } from "./$types";
import { API_BASE_PREFIX } from "$lib/utils";
import { API_BASE_PREFIX } from "$lib/server/utils";
export const load: PageServerLoad = async ({ params, fetch, cookies, url, parent, locals }) => {
const searchQuery = url.searchParams.get("article_search_query");

View File

@@ -1,5 +1,5 @@
import type { Actions, PageServerLoad } from "./$types";
import { API_BASE_PREFIX } from "$lib/utils";
import { API_BASE_PREFIX } from "$lib/server/utils";
export const load: PageServerLoad = async ({ parent, params, cookies, fetch }) => {
const articleData = await fetch(`${API_BASE_PREFIX}/article?id=eq.${params.articleId}`, {
@@ -14,7 +14,7 @@ export const load: PageServerLoad = async ({ parent, params, cookies, fetch }) =
const article = await articleData.json();
const { website } = await parent();
return { website, article };
return { website, article, API_BASE_PREFIX };
};
export const actions: Actions = {

View File

@@ -5,7 +5,7 @@
import SuccessOrError from "$lib/components/SuccessOrError.svelte";
import type { ActionData, PageServerData } from "./$types";
import Modal from "$lib/components/Modal.svelte";
import { API_BASE_PREFIX, handleImagePaste } from "$lib/utils";
import { handleImagePaste } from "$lib/utils";
const { data, form } = $props<{ data: PageServerData; form: ActionData }>();
@@ -19,7 +19,7 @@
};
const handlePaste = async (event: ClipboardEvent) => {
const newContent = await handleImagePaste(event);
const newContent = await handleImagePaste(event, data.API_BASE_PREFIX);
previewContent = newContent;
};
</script>
@@ -86,7 +86,7 @@
{#if data.article.cover_image}
<Modal id="preview-cover-article-{data.article.id}" text="Preview">
<img
src={`${API_BASE_PREFIX}/rpc/retrieve_file?id=${data.article.cover_image}`}
src={`${data.API_BASE_PREFIX}/rpc/retrieve_file?id=${data.article.cover_image}`}
alt=""
/>
</Modal>