From f30fb98f2f7173e9cbf3d7ecfe946b102217a232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksa=20Siri=C5=A1ki?= <31509435+aleksasiriski@users.noreply.github.com> Date: Fri, 10 Nov 2023 16:18:53 +0100 Subject: [PATCH 1/2] fix: correct usage of universal load function --- fly.toml | 4 ++-- src/routes/search/+page.server.ts | 20 -------------------- src/routes/search/+page.ts | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 32 deletions(-) delete mode 100644 src/routes/search/+page.server.ts diff --git a/fly.toml b/fly.toml index faddfda7..86901eae 100644 --- a/fly.toml +++ b/fly.toml @@ -6,8 +6,8 @@ primary_region = "cdg" [env] ORIGIN = "https://brzaguza.rs" - API_URL = "http://zadnjica.internal:3030" - PUBLIC_API_URL = "https://api.brzaguza.rs" + PUBLIC_API_URL_SSR = "http://zadnjica.internal:3030" + PUBLIC_API_URL_CSR = "https://api.brzaguza.rs" [http_service] internal_port = 3000 diff --git a/src/routes/search/+page.server.ts b/src/routes/search/+page.server.ts deleted file mode 100644 index 416ec65a..00000000 --- a/src/routes/search/+page.server.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { PageServerLoad } from './$types'; -import { env } from '$env/dynamic/private'; - -export const load: PageServerLoad = async ({ fetch, url }) => { - const q = url.searchParams.get('q'); - if (q === null || q === '') { - return { - query: '', - results: [] - }; - } - const apiUrl = `${env.API_URL}/search?${url.searchParams}`; - const response = await fetch(apiUrl); - const results = await response.json(); - - return { - query: q, - results: results - }; -}; diff --git a/src/routes/search/+page.ts b/src/routes/search/+page.ts index 9b758b88..be4e4d46 100644 --- a/src/routes/search/+page.ts +++ b/src/routes/search/+page.ts @@ -1,16 +1,8 @@ import type { PageLoad } from './$types'; import { env } from '$env/dynamic/public'; +import { browser } from '$app/environment'; export const load: PageLoad = async ({ data, fetch, url }) => { - // this runs on SSR (+page.server.ts) - if (data != null) { - return { - query: data.query, - results: data.results - }; - } - - // this runs on CSR const q = url.searchParams.get('q'); if (q === null || q === '') { return { @@ -18,7 +10,15 @@ export const load: PageLoad = async ({ data, fetch, url }) => { results: [] }; } - const apiUrl = `${env.PUBLIC_API_URL}/search?${url.searchParams}`; + + let apiUri; + if (!browser) { + apiUri = env.PUBLIC_API_URL_SSR; + } else { + apiUri = env.PUBLIC_API_URL_CSR; + } + + const apiUrl = `${apiUri}/search?${url.searchParams}`; const response = await fetch(apiUrl); const results = await response.json(); From afdac6af7bad16ec627ac4ae10091d911fd72ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksa=20Siri=C5=A1ki?= <31509435+aleksasiriski@users.noreply.github.com> Date: Fri, 10 Nov 2023 16:28:25 +0100 Subject: [PATCH 2/2] fix: remove data from load, better docker ignore and fix env example --- .dockerignore | 8 ++++---- .env.example | 4 ++-- src/routes/search/+page.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.dockerignore b/.dockerignore index 19d91c9c..ae710bb8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,4 @@ -fly.toml -.dockerignore -.github -.env* \ No newline at end of file +** +!docker/ +!build/ +!package.json \ No newline at end of file diff --git a/.env.example b/.env.example index 2fbad75a..6b5f204a 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,3 @@ ORIGIN=http://localhost:5173 # this server -API_URL=http://localhost:3030 # server reachable -PUBLIC_API_URL=http://localhost:3030 # client reachable \ No newline at end of file +PUBLIC_API_URL_SSR=http://localhost:3030 # server reachable +PUBLIC_API_URL_CSR=http://localhost:3030 # client reachable \ No newline at end of file diff --git a/src/routes/search/+page.ts b/src/routes/search/+page.ts index be4e4d46..e2e85246 100644 --- a/src/routes/search/+page.ts +++ b/src/routes/search/+page.ts @@ -2,7 +2,7 @@ import type { PageLoad } from './$types'; import { env } from '$env/dynamic/public'; import { browser } from '$app/environment'; -export const load: PageLoad = async ({ data, fetch, url }) => { +export const load: PageLoad = async ({ fetch, url }) => { const q = url.searchParams.get('q'); if (q === null || q === '') { return {