From d33fc7f1df66c1e451c5d79ab59a5bc9dce4e496 Mon Sep 17 00:00:00 2001
From: Tomas <tomasysh@gmail.com>
Date: 星期四, 14 九月 2023 18:01:18 +0800
Subject: [PATCH] Update: http 攔截器,檢查 base url 的檢查 method

---
 PAMapp/shared/services/httpClient.ts |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/PAMapp/shared/services/httpClient.ts b/PAMapp/shared/services/httpClient.ts
index c0b08f2..08a5b6e 100644
--- a/PAMapp/shared/services/httpClient.ts
+++ b/PAMapp/shared/services/httpClient.ts
@@ -10,10 +10,23 @@
   '/eService/authenticate',
   '/login/validate/get_img_code',
   '/login/validate/verify_img_code',
+  '/api/access_analysis/insert'
 ];
 
+function getBaseUrl(): string {
+  const baseUrl = process.env.BASE_URL;
+  if (!baseUrl) {
+    throw new Error('BASE_URL is not defined in process.env');
+  }
+  // const pattern = /^(https?:\/\/)[\w.-]+(:\d+)?/i; // �����RL撽��
+  // if (!pattern.test(baseUrl)) {
+  //   throw new Error('Invalid BASE_URL');
+  // }
+  // 銝�閬���RL嚗�摰歇蝬蝯�RL
+  return baseUrl;
+}
 export const http = axios.create({
-  baseURL: process.env.BASE_URL,
+  baseURL: getBaseUrl(), // 雿輻�������aseURL
   withCredentials: true
 });
 
@@ -48,7 +61,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