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 { LayoutServerLoad } from "./$types";
import { API_BASE_PREFIX } from "$lib/utils";
import { API_BASE_PREFIX } from "$lib/server/utils";
import { error } from "@sveltejs/kit";
export const load: LayoutServerLoad = async ({ params, fetch, cookies }) => {

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 }) => {
const globalSettingsData = await fetch(
@@ -39,7 +39,8 @@ export const load: PageServerLoad = async ({ params, fetch, cookies, url }) => {
return {
globalSettings,
header,
footer
footer,
API_BASE_PREFIX
};
};

View File

@@ -5,7 +5,6 @@
import SuccessOrError from "$lib/components/SuccessOrError.svelte";
import type { ActionData, PageServerData } from "./$types";
import Modal from "$lib/components/Modal.svelte";
import { API_BASE_PREFIX } from "$lib/utils";
const { data, form } = $props<{ data: PageServerData; form: ActionData }>();
@@ -19,7 +18,7 @@
};
const handlePaste = async (event: ClipboardEvent) => {
const newContent = await handleImagePaste(event);
const newContent = await handleImagePaste(event, data.API_BASE_PREFIX);
previewContent = newContent;
};
</script>
@@ -72,7 +71,7 @@
{#if data.globalSettings.favicon_image}
<Modal id="preview-favicon-global-{data.globalSettings.website_id}" text="Preview">
<img
src={`${API_BASE_PREFIX}/rpc/retrieve_file?id=${data.globalSettings.favicon_image}`}
src={`${data.API_BASE_PREFIX}/rpc/retrieve_file?id=${data.globalSettings.favicon_image}`}
alt=""
/>
</Modal>
@@ -125,7 +124,10 @@
</label>
{#if data.header.logo_image}
<Modal id="preview-logo-header-{data.header.website_id}" text="Preview">
<img src={`${API_BASE_PREFIX}/rpc/retrieve_file?id=${data.header.logo_image}`} alt="" />
<img
src={`${data.API_BASE_PREFIX}/rpc/retrieve_file?id=${data.header.logo_image}`}
alt=""
/>
</Modal>
{/if}
</div>

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>

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, fetch, cookies }) => {
const { website, home } = await parent();

View File

@@ -2,12 +2,13 @@ import { readFile, mkdir, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { md } from "$lib/utils";
import type { Actions, PageServerLoad } from "./$types";
import { API_BASE_PREFIX, NGINX_BASE_PREFIX } from "$lib/utils";
import { API_BASE_PREFIX } from "$lib/server/utils";
import { render } from "svelte/server";
import BlogIndex from "$lib/templates/blog/BlogIndex.svelte";
import BlogArticle from "$lib/templates/blog/BlogArticle.svelte";
import DocsIndex from "$lib/templates/docs/DocsIndex.svelte";
import DocsEntry from "$lib/templates/docs/DocsEntry.svelte";
import { dev } from "$app/environment";
export const load: PageServerLoad = async ({ params, fetch, cookies }) => {
const websiteOverviewData = await fetch(
@@ -26,7 +27,7 @@ export const load: PageServerLoad = async ({ params, fetch, cookies }) => {
generateStaticFiles(websiteOverview);
const websitePreviewUrl = `${NGINX_BASE_PREFIX}/previews/${websiteOverview.id}/index.html`;
const websitePreviewUrl = `${dev ? "http://localhost:18000" : ""}/previews/${websiteOverview.id}/index.html`;
return {
websiteOverview,