From 06eb6c1f9183d79df455d5ab95195b16d8cee146 Mon Sep 17 00:00:00 2001 From: db8200 <75286062+db8200@users.noreply.github.com> Date: Sun, 23 Jul 2023 06:11:29 +0200 Subject: [PATCH] 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> --- frontend/components/global/PageQRCode.vue | 4 +++- frontend/lib/api/base/base-api.ts | 5 +++-- frontend/lib/api/base/urls.ts | 6 +++--- frontend/pages/reports/label-generator.vue | 4 +++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/frontend/components/global/PageQRCode.vue b/frontend/components/global/PageQRCode.vue index d6d0a11..2c6e5a8 100644 --- a/frontend/components/global/PageQRCode.vue +++ b/frontend/components/global/PageQRCode.vue @@ -15,10 +15,12 @@ diff --git a/frontend/lib/api/base/base-api.ts b/frontend/lib/api/base/base-api.ts index 3847a4b..358779a 100644 --- a/frontend/lib/api/base/base-api.ts +++ b/frontend/lib/api/base/base-api.ts @@ -1,4 +1,5 @@ import { Requests } from "../../requests"; +import { route } from "."; const ZERO_DATE = "0001-01-01T00:00:00Z"; @@ -70,12 +71,12 @@ export class BaseAPI { this.attachmentToken = attachmentToken; } - // if a attachmentToken is present it will be added to URL as a query param + // if an attachmentToken is present, it will be added to URL as a query param // this is done with a simple appending of the query param to the URL. If your // URL already has a query param, this will not work. authURL(url: string): string { if (this.attachmentToken) { - return `/api/v1${url}?access_token=${this.attachmentToken}`; + return route(url, { access_token: this.attachmentToken }); } return url; } diff --git a/frontend/lib/api/base/urls.ts b/frontend/lib/api/base/urls.ts index 31e263d..47a1c5b 100644 --- a/frontend/lib/api/base/urls.ts +++ b/frontend/lib/api/base/urls.ts @@ -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 { const url = new URL(parts.prefix + rest, parts.host); diff --git a/frontend/pages/reports/label-generator.vue b/frontend/pages/reports/label-generator.vue index da3bbd7..780a0c4 100644 --- a/frontend/pages/reports/label-generator.vue +++ b/frontend/pages/reports/label-generator.vue @@ -1,4 +1,6 @@