From 1e8fb5971367812c11bb237637efbf36da7b0c9c Mon Sep 17 00:00:00 2001 From: Tomas <tomasysh@gmail.com> Date: 星期五, 01 九月 2023 13:37:36 +0800 Subject: [PATCH] Update: P12.1 URL manipulation --- PAMapp/shared/services/httpClient.ts | 15 ++++++++++++--- 1 files changed, 12 insertions(+), 3 deletions(-) diff --git a/PAMapp/shared/services/httpClient.ts b/PAMapp/shared/services/httpClient.ts index a015cd1..82c83d8 100644 --- a/PAMapp/shared/services/httpClient.ts +++ b/PAMapp/shared/services/httpClient.ts @@ -13,11 +13,20 @@ '/api/access_analysis/insert' ]; -const BASE_URL = process.env.BASE_URL; +const BASE_URL = process.env.BASE_URL!; + +function sanitizeBaseUrl(baseUrl: string): string { + const isValidBaseUrl = (url: string) => url.includes('api'); + if (isValidBaseUrl(baseUrl)) { + return baseUrl; + } else { + throw new Error('Invalid BASE_URL'); + } +} export const http = axios.create({ - baseURL: BASE_URL, - withCredentials: true, + baseURL: sanitizeBaseUrl(BASE_URL), + withCredentials: true }); let apiNumber = 0; -- Gitblit v1.8.0