72 lines
1.9 KiB
TypeScript
72 lines
1.9 KiB
TypeScript
import axios from "axios";
|
|
import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
|
|
|
|
interface SignupClientConfig {
|
|
baseURL: string;
|
|
}
|
|
|
|
class SignupClient {
|
|
private static instance: SignupClient;
|
|
private axiosInstance: AxiosInstance;
|
|
|
|
private constructor(config: SignupClientConfig) {
|
|
this.axiosInstance = axios.create({
|
|
baseURL: config.baseURL,
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
withCredentials: true,
|
|
});
|
|
|
|
// 인증 토큰 없이도 요청할 수 있도록 인터셉터 설정
|
|
this.axiosInstance.interceptors.request.use((config) => {
|
|
// 인증 토큰을 자동으로 추가하지 않음
|
|
return config;
|
|
});
|
|
}
|
|
|
|
public static getInstance(config: SignupClientConfig): SignupClient {
|
|
if (!SignupClient.instance) {
|
|
SignupClient.instance = new SignupClient(config);
|
|
}
|
|
return SignupClient.instance;
|
|
}
|
|
|
|
public async get<T = unknown, R = AxiosResponse<T>>(
|
|
url: string,
|
|
config?: AxiosRequestConfig
|
|
): Promise<R> {
|
|
const response = await this.axiosInstance.get<T, R>(url, config);
|
|
return response;
|
|
}
|
|
|
|
public async post<T = unknown, R = AxiosResponse<T>, D = unknown>(
|
|
url: string,
|
|
data?: D,
|
|
config?: AxiosRequestConfig<D>
|
|
): Promise<R> {
|
|
const response = await this.axiosInstance.post<T, R>(url, data, config);
|
|
return response;
|
|
}
|
|
|
|
public async put<T = unknown, R = AxiosResponse<T>, D = unknown>(
|
|
url: string,
|
|
data?: D,
|
|
config?: AxiosRequestConfig<D>
|
|
): Promise<R> {
|
|
const response = await this.axiosInstance.put<T, R>(url, data, config);
|
|
return response;
|
|
}
|
|
|
|
public async delete<T = unknown, R = AxiosResponse<T>>(
|
|
url: string,
|
|
config?: AxiosRequestConfig
|
|
): Promise<R> {
|
|
const response = await this.axiosInstance.delete<T, R>(url, config);
|
|
return response;
|
|
}
|
|
}
|
|
|
|
export type { SignupClientConfig };
|
|
export { SignupClient };
|