|
1 | | -import type { |
2 | | - BaseQueryFn, |
3 | | - FetchArgs, |
4 | | - FetchBaseQueryError, |
5 | | -} from '@reduxjs/toolkit/query'; |
6 | 1 | import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'; |
7 | 2 |
|
8 | 3 | import { ENV_CONFIG } from '@/shared/config'; |
9 | 4 |
|
10 | | -const baseQuery = fetchBaseQuery({ |
11 | | - baseUrl: ENV_CONFIG.API_URL, |
12 | | - credentials: 'include', |
13 | | - prepareHeaders: (headers) => { |
14 | | - headers.set('Content-Type', 'application/json'); |
15 | | - return headers; |
16 | | - }, |
17 | | - fetchFn: async (input, init) => { |
18 | | - const url = typeof input === 'string' ? input : input.url; |
19 | | - const fullUrl = url.startsWith('http') |
20 | | - ? url |
21 | | - : `${ENV_CONFIG.API_URL}${url}`; |
22 | | - |
23 | | - const response = await fetch(fullUrl, { |
24 | | - ...init, |
25 | | - credentials: 'include', |
26 | | - mode: 'cors', |
27 | | - headers: { |
28 | | - ...init?.headers, |
29 | | - 'Content-Type': 'application/json', |
30 | | - }, |
31 | | - }); |
32 | | - |
33 | | - return response; |
34 | | - }, |
35 | | -}); |
36 | | - |
37 | | -const baseQueryWithReauth: BaseQueryFn< |
38 | | - string | FetchArgs, |
39 | | - unknown, |
40 | | - FetchBaseQueryError |
41 | | -> = async (args, api, extraOptions) => { |
42 | | - const result = await baseQuery(args, api, extraOptions); |
43 | | - return result; |
44 | | -}; |
45 | | - |
46 | 5 | export const api = createApi({ |
47 | 6 | reducerPath: 'api', |
48 | | - baseQuery: baseQueryWithReauth, |
| 7 | + baseQuery: fetchBaseQuery({ |
| 8 | + baseUrl: ENV_CONFIG.API_URL, |
| 9 | + credentials: 'include', |
| 10 | + prepareHeaders: (headers) => { |
| 11 | + headers.set('Content-Type', 'application/json'); |
| 12 | + return headers; |
| 13 | + }, |
| 14 | + }), |
49 | 15 | tagTypes: ['genres', 'movies', 'currentMovie', 'user'], |
50 | 16 | endpoints: () => ({}), |
51 | 17 | }); |
0 commit comments