From 68803282fec1d93778dd9f6b4ba534ed23a63137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksa=20Siri=C5=A1ki?= <31509435+aleksasiriski@users.noreply.github.com> Date: Sun, 3 Dec 2023 16:28:41 +0100 Subject: [PATCH 1/2] fix: only ssr loading --- src/routes/search/{+page.ts => +page.server.ts} | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) rename src/routes/search/{+page.ts => +page.server.ts} (70%) diff --git a/src/routes/search/+page.ts b/src/routes/search/+page.server.ts similarity index 70% rename from src/routes/search/+page.ts rename to src/routes/search/+page.server.ts index e6562dc9..209ae97e 100644 --- a/src/routes/search/+page.ts +++ b/src/routes/search/+page.server.ts @@ -1,7 +1,6 @@ import { env } from '$env/dynamic/public'; -import { browser } from '$app/environment'; -import type { PageLoad } from './$types'; +import type { PageServerLoad } from './$types'; import type { Result } from './types'; async function fetchResultsJSON( @@ -24,7 +23,7 @@ async function fetchResultsJSON( return results; } -export const load: PageLoad = async ({ fetch, setHeaders, url }) => { +export const load: PageServerLoad = async ({ fetch, setHeaders, url }) => { const q = url.searchParams.get('q'); if (q === null || q === '') { const results: Result[] = []; @@ -36,20 +35,15 @@ export const load: PageLoad = async ({ fetch, setHeaders, url }) => { }; } - let apiUri; - if (!browser) { - apiUri = env.PUBLIC_API_URL_SSR; - } else { - apiUri = env.PUBLIC_API_URL_CSR; - } + const apiUri = env.PUBLIC_API_URL_SSR; const apiUrl = `${apiUri}/search?${url.searchParams}`; - const results = fetchResultsJSON(fetch, setHeaders, apiUrl); + const results = await fetchResultsJSON(fetch, setHeaders, apiUrl); return { query: q, streamed: { - results: browser ? results : await results + results: results } }; }; From 0c13f6b2cc2e9961679493836fce766a2bcd9ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksa=20Siri=C5=A1ki?= <31509435+aleksasiriski@users.noreply.github.com> Date: Sun, 3 Dec 2023 16:29:35 +0100 Subject: [PATCH 2/2] chore: remove readme --- README.md | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 5c91169b..00000000 --- a/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# create-svelte - -Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte). - -## Creating a project - -If you're seeing this, you've probably already done this step. Congrats! - -```bash -# create a new project in the current directory -npm create svelte@latest - -# create a new project in my-app -npm create svelte@latest my-app -``` - -## Developing - -Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server: - -```bash -npm run dev - -# or start the server and open the app in a new browser tab -npm run dev -- --open -``` - -## Building - -To create a production version of your app: - -```bash -npm run build -``` - -You can preview the production build with `npm run preview`. - -> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.