Skip to content

Commit d4967d3

Browse files
feat: strip trailing slash
Closes #57 Update urls.ts
1 parent 409436c commit d4967d3

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

src/frontend/package-lock.json

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/frontend/src/lib/consts/backend.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { env } from '$env/dynamic/public';
2+
import { strip_trailing_slash } from '$lib/functions/urls';
3+
const envrionment_variable = env.PUBLIC_BACKEND_API ?? 'http://localhost:8000';
24

3-
export const BACKEND_API = env.PUBLIC_BACKEND_API ?? 'http://localhost:8000';
5+
export const BACKEND_API = strip_trailing_slash(envrionment_variable);
46
export const LOGIN_URL = `${BACKEND_API}/login`;
57
export const USER_URL = `${BACKEND_API}/user`;
68
export const CONFIG_URL = `${BACKEND_API}/config`;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
export function resolve_partial_path(path: string) {
22
return new URL(path, window.location.href).pathname;
33
}
4+
5+
export function strip_trailing_slash(input: string) {
6+
if (!input || input === '/') return input;
7+
8+
// Split off query string and hash
9+
const [path, query = ''] = input.split('?');
10+
const [cleanPath, hash = ''] = path.split('#');
11+
12+
const normalizedPath = cleanPath.replace(/\/+$/, '');
13+
14+
return normalizedPath + (query ? '?' + query : '') + (hash ? '#' + hash : '');
15+
}

0 commit comments

Comments
 (0)