landing page added
This commit is contained in:
29
src/shared/request/apiRequest.ts
Normal file
29
src/shared/request/apiRequest.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||
|
||||
import { getRouteLang } from './getLanguage';
|
||||
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL;
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: baseUrl,
|
||||
});
|
||||
|
||||
export const apiRequest = async <T>(
|
||||
method: 'GET' | 'POST' | 'PUT' | 'DELETE',
|
||||
url: string,
|
||||
data?: unknown,
|
||||
config?: Omit<AxiosRequestConfig, 'method' | 'url' | 'data'>,
|
||||
): Promise<T> => {
|
||||
const response: AxiosResponse<T> = await api.request<T>({
|
||||
method,
|
||||
url,
|
||||
data,
|
||||
...config,
|
||||
headers: {
|
||||
'Accept-Language': getRouteLang(), // evaluated per-request
|
||||
...config?.headers,
|
||||
},
|
||||
});
|
||||
|
||||
return response.data;
|
||||
};
|
||||
Reference in New Issue
Block a user