From 0632b21db7576e4a223eb4f6ca09b650616222f2 Mon Sep 17 00:00:00 2001 From: Tomas <tomasysh@gmail.com> Date: 星期三, 17 一月 2024 09:54:09 +0800 Subject: [PATCH] Fixed: 移除 lodash, @type/lodash 導致的 side-effect --- PAMapp/shared/services/httpClient.ts | 30 +++++++++++++++++++++--------- 1 files changed, 21 insertions(+), 9 deletions(-) diff --git a/PAMapp/shared/services/httpClient.ts b/PAMapp/shared/services/httpClient.ts index a015cd1..8fe7bad 100644 --- a/PAMapp/shared/services/httpClient.ts +++ b/PAMapp/shared/services/httpClient.ts @@ -1,6 +1,4 @@ -import { AxiosRequestConfig, AxiosError, AxiosResponse} from 'axios'; -import axios from 'axios'; -import _ from 'lodash'; +import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios'; import messageBoxService from './message-box.service'; @@ -13,11 +11,21 @@ '/api/access_analysis/insert' ]; -const BASE_URL = process.env.BASE_URL; - +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: BASE_URL, - withCredentials: true, + baseURL: getBaseUrl(), // 雿輻�������aseURL + withCredentials: true }); let apiNumber = 0; @@ -76,11 +84,15 @@ messageBoxService.showErrorMessage('', error); return } - if (!_.includes(notRequireInterceptorErrorUrl, error.config.url)) { + if (!notRequireInterceptorErrorUrl.includes(error.config.url)) { switch (error.response.status) { case 401: Promise.all([messageBoxService.showErrorMessage('���暹��'), window.$nuxt.$store.dispatch('localStorage/actionStorageClear')]).then(() => { - _.isEqual(window.$nuxt.$route.name, 'index') ? location.reload() : window.$nuxt.$router.push('/'); + if (window.$nuxt.$route.name === 'index') { + location.reload(); + } else { + window.$nuxt.$router.push('/'); + } }); break; -- Gitblit v1.8.0