mirror of
https://github.com/hay-kot/homebox.git
synced 2025-06-04 11:32:28 +00:00
conform casing and documentation
This commit is contained in:
parent
572f0f6689
commit
a9f271d8c1
9 changed files with 58 additions and 50 deletions
|
@ -3,14 +3,23 @@ const parts = {
|
|||
prefix: '/api/v1',
|
||||
};
|
||||
|
||||
export function OverrideParts(host: string, prefix: string) {
|
||||
export function overrideParts(host: string, prefix: string) {
|
||||
parts.host = host;
|
||||
parts.prefix = prefix;
|
||||
}
|
||||
|
||||
export type QueryValue = string | string[] | number | number[] | boolean | null | undefined;
|
||||
|
||||
export function UrlBuilder(rest: string, params: Record<string, QueryValue> = {}): string {
|
||||
/**
|
||||
* route is a the main URL builder for the API. It will use a predefined host and prefix (global)
|
||||
* in the urls.ts file and then append the passed in path parameter uring the `URL` class from the
|
||||
* browser. It will also append any query parameters passed in as the second parameter.
|
||||
*
|
||||
* The default host `http://localhost.com` is removed from the path if it is present. This allows us
|
||||
* to bootstrap the API with different hosts as needed (like for testing) but still allows us to use
|
||||
* relative URLs in pruduction because the API and client bundle are served from the same server/host.
|
||||
*/
|
||||
export function route(rest: string, params: Record<string, QueryValue> = {}): string {
|
||||
const url = new URL(parts.prefix + rest, parts.host);
|
||||
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
|
@ -23,6 +32,5 @@ export function UrlBuilder(rest: string, params: Record<string, QueryValue> = {}
|
|||
}
|
||||
}
|
||||
|
||||
// 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