forked from mirrors/homebox
fix 3 places where API URLs were not constructed by function route (#451)
* Fixed 3 places where API URLs were not constructed by function route(path, params).
* autofix
---------
Co-authored-by: Hayden <64056131+hay-kot@users.noreply.github.com>
Former-commit-id: 06eb6c1f91
This commit is contained in:
parent
4b071bccda
commit
0eb0b283b2
4 changed files with 12 additions and 7 deletions
|
@ -11,13 +11,13 @@ export function overrideParts(host: string, prefix: string) {
|
|||
export type QueryValue = string | string[] | number | number[] | boolean | null | undefined;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* route is 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 using 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.
|
||||
* relative URLs in production 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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue