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 |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/PAMapp/shared/services/httpClient.ts b/PAMapp/shared/services/httpClient.ts
index c0b08f2..82c83d8 100644
--- a/PAMapp/shared/services/httpClient.ts
+++ b/PAMapp/shared/services/httpClient.ts
@@ -10,10 +10,22 @@
   '/eService/authenticate',
   '/login/validate/get_img_code',
   '/login/validate/verify_img_code',
+  '/api/access_analysis/insert'
 ];
 
+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: process.env.BASE_URL,
+  baseURL: sanitizeBaseUrl(BASE_URL),
   withCredentials: true
 });
 
@@ -48,7 +60,8 @@
 
 function addHttpHeader(config: AxiosRequestConfig): void {
   config.headers = {
-    Authorization: 'Bearer ' + localStorage.getItem('id_token')
+    Authorization: 'Bearer ' + localStorage.getItem('id_token'),
+    'content-type': 'application/json'
   }
 }
 

--
Gitblit v1.8.0