mirror of
https://github.com/hay-kot/homebox.git
synced 2025-06-04 11:32:28 +00:00
move to nuxt
This commit is contained in:
parent
890eb55d27
commit
26ecb5a9d4
93 changed files with 5273 additions and 4749 deletions
31
frontend/lib/api/base/urls.ts
Normal file
31
frontend/lib/api/base/urls.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
export const prefix = '/api/v1';
|
||||
|
||||
export type QueryValue =
|
||||
| string
|
||||
| string[]
|
||||
| number
|
||||
| number[]
|
||||
| boolean
|
||||
| null
|
||||
| undefined;
|
||||
|
||||
export function UrlBuilder(
|
||||
rest: string,
|
||||
params: Record<string, QueryValue> = {}
|
||||
): string {
|
||||
// we use a stub base URL to leverage the URL class
|
||||
const url = new URL(prefix + rest, 'http://localhost.com');
|
||||
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
if (Array.isArray(value)) {
|
||||
for (const item of value) {
|
||||
url.searchParams.append(key, String(item));
|
||||
}
|
||||
} else {
|
||||
url.searchParams.append(key, String(value));
|
||||
}
|
||||
}
|
||||
|
||||
// we return the path only, without the base URL
|
||||
return url.toString().replace('http://localhost.com', '');
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue