Skip to content

Commit

Permalink
Change API to REACT_APP_API
Browse files Browse the repository at this point in the history
  • Loading branch information
marcobrunodev committed Oct 1, 2019
1 parent 0106476 commit d6dfa4a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"styled-components": "^4.3.2"
},
"scripts": {
"start": "react-scripts start",
"start": "REACT_APP_API=http://localhost:5000 react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
Expand Down
6 changes: 2 additions & 4 deletions src/containers/DetailsService/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const DetailsService = ({ id }) => {
})

const { title, description, week, site, address, district, photo } = service
const { API } = process.env
const { REACT_APP_API } = process.env

const printDay = day => {
try {
Expand All @@ -126,9 +126,7 @@ const DetailsService = ({ id }) => {

useEffect(() => {
async function getService() {
const res = await axios.get(
`${API || 'http://localhost:5000'}/business/${id}`
)
const res = await axios.get(`${REACT_APP_API}/business/${id}`)
setService(res.data)
}

Expand Down
21 changes: 8 additions & 13 deletions src/containers/MainMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ const MainMenu = ({ active, closeMenu, openMenu, updateBusiness }) => {
const [categories, setCategories] = useState([])

useEffect(() => {
const { API_HOST } = process.env
const { REACT_APP_API } = process.env
const featchData = async () => {
const res = await axios.get(
`${API_HOST || 'http://localhost:5000'}/category`
)
console.log('URL', `${API_HOST || 'http://localhost:5000'}/category`)
const res = await axios.get(`${REACT_APP_API}/category`)
console.log('URL', `${REACT_APP_API}/category`)
console.log('category', res.data)

setCategories(() => res.data)
Expand All @@ -24,21 +22,18 @@ const MainMenu = ({ active, closeMenu, openMenu, updateBusiness }) => {
}, [])

useEffect(() => {
const { API } = process.env
const { REACT_APP_API } = process.env

const getServicesByActiveCategories = async () => {
const activeCategories = categories
.filter(category => category.active)
.map(category => category.content)

const { data } = await axios.get(
`${API || 'http://localhost:5000'}/business/categories`,
{
params: {
categories: activeCategories
}
const { data } = await axios.get(`${REACT_APP_API}/business/categories`, {
params: {
categories: activeCategories
}
)
})

updateBusiness(data)
}
Expand Down
13 changes: 5 additions & 8 deletions src/containers/ServiceForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@ const ServiceForm = () => {
})
const [categories, setCategories] = useState([])
const [photo, setPhoto] = useState()
const { API } = process.env
const { REACT_APP_API } = process.env

const send = async () => {
const {
data: { location }
} = await axios.post(
`${API || 'http://localhost:5000'}/business/photo`,
photo
)
await axios.post(`${API || 'http://localhost:5000'}/business`, {
} = await axios.post(`${REACT_APP_API}/business/photo`, photo)
await axios.post(`${REACT_APP_API}/business`, {
...service,
photo: location
})
Expand Down Expand Up @@ -74,12 +71,12 @@ const ServiceForm = () => {

useEffect(() => {
async function getAllCategories() {
const res = await axios.get(`${API || 'http://localhost:5000'}/category`)
const res = await axios.get(`${REACT_APP_API}/category`)
setCategories(res.data)
}

getAllCategories()
}, [API])
}, [])

return (
<WrapperCard>
Expand Down

0 comments on commit d6dfa4a

Please sign in to comment.