Skip to content

Commit

Permalink
Merge pull request #32 from tminaorg/correct-usage-of-uni-load
Browse files Browse the repository at this point in the history
fix: Correct usage of uni load
  • Loading branch information
aleksasiriski authored Nov 10, 2023
2 parents d6ea2d4 + afdac6a commit 2cd2822
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 39 deletions.
8 changes: 4 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fly.toml
.dockerignore
.github
.env*
**
!docker/
!build/
!package.json
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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
PUBLIC_API_URL_SSR=http://localhost:3030 # server reachable
PUBLIC_API_URL_CSR=http://localhost:3030 # client reachable
4 changes: 2 additions & 2 deletions fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions src/routes/search/+page.server.ts

This file was deleted.

22 changes: 11 additions & 11 deletions src/routes/search/+page.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
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
export const load: PageLoad = async ({ fetch, url }) => {
const q = url.searchParams.get('q');
if (q === null || q === '') {
return {
query: '',
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();

Expand Down

0 comments on commit 2cd2822

Please sign in to comment.