| | |
| | | '/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; // 更嚴格的URL驗證 |
| | | // if (!pattern.test(baseUrl)) { |
| | | // throw new Error('Invalid BASE_URL'); |
| | | // } |
| | | // 不需要再清理URL,因為它已經是絕對URL |
| | | return baseUrl; |
| | | } |
| | | export const http = axios.create({ |
| | | baseURL: process.env.BASE_URL, |
| | | baseURL: getBaseUrl(), // 使用函數動態獲取baseURL |
| | | withCredentials: true |
| | | }); |
| | | |
| | |
| | | |
| | | function addHttpHeader(config: AxiosRequestConfig): void { |
| | | config.headers = { |
| | | Authorization: 'Bearer ' + localStorage.getItem('id_token') |
| | | Authorization: 'Bearer ' + localStorage.getItem('id_token'), |
| | | 'content-type': 'application/json' |
| | | } |
| | | } |
| | | |