保誠-保戶業務員媒合平台
Tomas
2023-09-05 0de81c2b3f56f57121f6a9f911c599cef70eeeb2
Update: 0901-P5 URL manipulation
修改1個檔案
14 ■■■■ 已變更過的檔案
PAMapp/shared/services/httpClient.ts 14 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
PAMapp/shared/services/httpClient.ts
@@ -16,14 +16,20 @@
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 {
  const pattern = /^(https?:\/\/).+/i;
  if (!pattern.test(baseUrl)) {
    throw new Error('Invalid BASE_URL');
  }
  const cleanedBaseUrl = cleanUrl(baseUrl);
  return cleanedBaseUrl;
}
function cleanUrl(url: string): string {
  const cleanedUrl = url.replace(/[^a-zA-Z0-9:/._-]/g, '');
  return cleanedUrl;
}
export const http = axios.create({
  baseURL: sanitizeBaseUrl(BASE_URL),
  withCredentials: true