From efe3c4aafe78e90acd5849523a0e2a1ff7bc2b8f Mon Sep 17 00:00:00 2001 From: Marco Bruno Date: Tue, 1 Oct 2019 03:02:52 +0100 Subject: [PATCH] Add process.env.API --- src/containers/DetailsService/index.js | 7 ++++--- src/containers/MainMenu/index.js | 9 +++++++-- src/containers/ServiceForm/index.js | 12 ++++++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/containers/DetailsService/index.js b/src/containers/DetailsService/index.js index 2f05631..ded04ab 100644 --- a/src/containers/DetailsService/index.js +++ b/src/containers/DetailsService/index.js @@ -25,8 +25,6 @@ import { WrapperWeekly } from './styles' -import cafe from '../../img/cafe.jpg' - const DetailsService = ({ id }) => { const [service, setService] = useState({ address: 'carregando...', @@ -114,6 +112,7 @@ const DetailsService = ({ id }) => { }) const { title, description, week, site, address, district, photo } = service + const { API } = process.env const printDay = day => { try { @@ -127,7 +126,9 @@ const DetailsService = ({ id }) => { useEffect(() => { async function getService() { - const res = await axios.get(`http://localhost:5000/business/${id}`) + const res = await axios.get( + `${API || 'http://localhost:5000'}/business/${id}` + ) setService(res.data) } diff --git a/src/containers/MainMenu/index.js b/src/containers/MainMenu/index.js index 864a6ba..b48bea7 100644 --- a/src/containers/MainMenu/index.js +++ b/src/containers/MainMenu/index.js @@ -9,8 +9,11 @@ const MainMenu = ({ active, closeMenu, openMenu, updateBusiness }) => { const [categories, setCategories] = useState([]) useEffect(() => { + const { API } = process.env const featchData = async () => { - const res = await axios.get('http://localhost:5000/category') + const res = await axios.get(`${API || 'http://localhost:5000'}/category`) + console.log('URL', `${API || 'http://localhost:5000'}/category`) + console.log('category', res.data) setCategories(() => res.data) } @@ -19,13 +22,15 @@ const MainMenu = ({ active, closeMenu, openMenu, updateBusiness }) => { }, []) useEffect(() => { + const { API } = process.env + const getServicesByActiveCategories = async () => { const activeCategories = categories .filter(category => category.active) .map(category => category.content) const { data } = await axios.get( - `http://localhost:5000/business/categories`, + `${API || 'http://localhost:5000'}/business/categories`, { params: { categories: activeCategories diff --git a/src/containers/ServiceForm/index.js b/src/containers/ServiceForm/index.js index 3f7278c..98d7929 100644 --- a/src/containers/ServiceForm/index.js +++ b/src/containers/ServiceForm/index.js @@ -28,12 +28,16 @@ const ServiceForm = () => { }) const [categories, setCategories] = useState([]) const [photo, setPhoto] = useState() + const { API } = process.env const send = async () => { const { data: { location } - } = await axios.post('http://localhost:5000/business/photo', photo) - await axios.post('http://localhost:5000/business', { + } = await axios.post( + `${API || 'http://localhost:5000'}/business/photo`, + photo + ) + await axios.post(`${API || 'http://localhost:5000'}/business`, { ...service, photo: location }) @@ -70,12 +74,12 @@ const ServiceForm = () => { useEffect(() => { async function getAllCategories() { - const res = await axios.get('http://localhost:5000/category') + const res = await axios.get(`${API || 'http://localhost:5000'}/category`) setCategories(res.data) } getAllCategories() - }, []) + }, [API]) return (