diff --git a/.gitignore b/.gitignore index 4d29575..b59ec02 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ npm-debug.log* yarn-debug.log* yarn-error.log* +.env diff --git a/src/redux/Details/detailsSlice.js b/src/redux/Details/detailsSlice.js index 515b004..af109a7 100644 --- a/src/redux/Details/detailsSlice.js +++ b/src/redux/Details/detailsSlice.js @@ -1,12 +1,12 @@ import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'; import axios from 'axios'; +const baseUrl = process.env.REACT_APP_API_BASE_URL; export const fetchDetails = createAsyncThunk( 'details/fetchDetails', async (id, thunkApi) => { try { - const baseUrl = `https://rickandmortyapi.com/api/character/${id}`; - const response = await axios.get(baseUrl); + const response = await axios.get(`${baseUrl}/character/${id}`); return response.data; } catch (error) { return thunkApi.rejectWithValue(error.message); diff --git a/src/redux/characters/charactersSlice.js b/src/redux/characters/charactersSlice.js index 8be948a..46063e4 100644 --- a/src/redux/characters/charactersSlice.js +++ b/src/redux/characters/charactersSlice.js @@ -1,12 +1,12 @@ import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'; import axios from 'axios'; -const baseUrl = 'https://rickandmortyapi.com/api/characters'; +const baseUrl = process.env.REACT_APP_API_BASE_URL; export const fetchCharacters = createAsyncThunk( 'characters/fetchCharacters', async (thunkApi) => { try { - const response = await axios.get(baseUrl); + const response = await axios.get(`${baseUrl}/character`); return response.data; } catch (error) { return thunkApi.rejectWithValue(error.message); diff --git a/src/redux/episodes/episodesSlice.js b/src/redux/episodes/episodesSlice.js index 46f5c7c..2096770 100644 --- a/src/redux/episodes/episodesSlice.js +++ b/src/redux/episodes/episodesSlice.js @@ -1,12 +1,12 @@ import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'; import axios from 'axios'; -const baseUrl = 'https://rickandmortyapi.com/api/episode'; +const baseUrl = process.env.REACT_APP_API_URL; export const fetchEpisodes = createAsyncThunk( 'episodes/fetchEpisodes', async (thunkApi) => { try { - const response = await axios.get(baseUrl); + const response = await axios.get(`${baseUrl}/episode`); return response.data.results; } catch (error) { return thunkApi.rejectWithValue(error.message); diff --git a/src/redux/list/listSlice.js b/src/redux/list/listSlice.js index f83777b..ee8bf7e 100644 --- a/src/redux/list/listSlice.js +++ b/src/redux/list/listSlice.js @@ -1,13 +1,13 @@ import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'; import axios from 'axios'; -const baseUrl = 'https://rickandmortyapi.com/api/location/'; +const baseUrl = process.env.REACT_APP_API_BASE_URL; export const getLocation = createAsyncThunk( 'list/getLocation', async (thunkApi) => { try { - const response = await axios.get(baseUrl); + const response = await axios.get(`${baseUrl}/location`); return response.data.results; } catch (error) { return thunkApi.rejectWithValue(error.message);