From 9483aff4f99ceb996e85affe1fd108a95085b01f Mon Sep 17 00:00:00 2001 From: 0xLaurens <64641417+0xLaurens@users.noreply.github.com> Date: Sun, 29 Sep 2024 17:30:55 +0200 Subject: [PATCH] Fix: slash dotenv (#38) (#39) * Update README.md * Update README.md * Update README.md * Bump vite from 4.1.4 to 4.1.5 in /client Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 4.1.4 to 4.1.5. - [Release notes](https://github.com/vitejs/vite/releases) - [Changelog](https://github.com/vitejs/vite/blob/v4.1.5/packages/vite/CHANGELOG.md) - [Commits](https://github.com/vitejs/vite/commits/v4.1.5/packages/vite) --- updated-dependencies: - dependency-name: vite dependency-type: direct:development ... * Bump @sveltejs/kit from 1.11.0 to 1.15.2 in /client Bumps [@sveltejs/kit](https://github.com/sveltejs/kit/tree/HEAD/packages/kit) from 1.11.0 to 1.15.2. - [Release notes](https://github.com/sveltejs/kit/releases) - [Changelog](https://github.com/sveltejs/kit/blob/master/packages/kit/CHANGELOG.md) - [Commits](https://github.com/sveltejs/kit/commits/@sveltejs/kit@1.15.2/packages/kit) --- updated-dependencies: - dependency-name: "@sveltejs/kit" dependency-type: direct:development ... * Bump vite from 4.1.5 to 4.5.2 in /client Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 4.1.5 to 4.5.2. - [Release notes](https://github.com/vitejs/vite/releases) - [Changelog](https://github.com/vitejs/vite/blob/v4.5.2/packages/vite/CHANGELOG.md) - [Commits](https://github.com/vitejs/vite/commits/v4.5.2/packages/vite) --- updated-dependencies: - dependency-name: vite dependency-type: direct:development ... * Bump mio from 0.8.6 to 0.8.11 Bumps [mio](https://github.com/tokio-rs/mio) from 0.8.6 to 0.8.11. - [Release notes](https://github.com/tokio-rs/mio/releases) - [Changelog](https://github.com/tokio-rs/mio/blob/master/CHANGELOG.md) - [Commits](https://github.com/tokio-rs/mio/compare/v0.8.6...v0.8.11) --- updated-dependencies: - dependency-name: mio dependency-type: indirect ... * Add creating .env step (#36) * fix: slash in .env causing double slash (#37) --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Samuel Durante <44513615+samueldurantes@users.noreply.github.com> --- README.md | 5 ++--- client/src/routes/+page.svelte | 6 +++++- client/src/routes/+page.ts | 6 +++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bffe3a9..85a2eb0 100644 --- a/README.md +++ b/README.md @@ -51,10 +51,9 @@ Navigate into the frontend cd client ``` -Create a .env file containing the following variables - +Create a .env file in the `client` folder containing the following variables: ```sh -PUBLIC_API_URL=http://0.0.0.0:3000/ +PUBLIC_API_URL=http://0.0.0.0:3000 PUBLIC_WEBSOCKET_URL=ws://localhost:3000 ``` diff --git a/client/src/routes/+page.svelte b/client/src/routes/+page.svelte index d77cc54..28e9951 100644 --- a/client/src/routes/+page.svelte +++ b/client/src/routes/+page.svelte @@ -24,7 +24,11 @@ const reload = () => { toast.success("Reloaded rooms") - invalidate(`${env.PUBLIC_API_URL}/rooms`); + let url = `${env.PUBLIC_API_URL}`; + if (url.endsWith("/")) { + url = url.slice(0, -1); + } + invalidate(`${url}/rooms`); } diff --git a/client/src/routes/+page.ts b/client/src/routes/+page.ts index f678510..b73fb26 100644 --- a/client/src/routes/+page.ts +++ b/client/src/routes/+page.ts @@ -3,7 +3,11 @@ import {env} from "$env/dynamic/public"; export const load: PageLoad = async ({fetch}) => { try { - const res = await fetch(`${env.PUBLIC_API_URL}/rooms`); + let url = `${env.PUBLIC_API_URL}`; + if (url.endsWith("/")) { + url = url.slice(0, -1); + } + const res = await fetch(`${url}/rooms`); return await res.json(); } catch (e) { return {