I have a MERN application that uses a combination of:
- Async/Await with Axios, and
- Redux
to manage the data flow throughout my application. Redux is mainly used for login + authorization (along these lines). A few other tables that are shared across many pages on my app are fetched through redux and accessible via reduxState. However, since most of the routes in my MERN app do not require shared state, I simply use axios for the majority of data fetching from my Mongo database.
I am currently having a problem with only the redux fetches, both for login/authorization as well as for all of the other tables fetched through redux. In my console, I am receiving the following errors on redux actions:
The node API for the app is served on port 8080, and if I copy this url, change the port, and paste http://localhost:8080/api/cbb/teams/list
directly into my chrome browser, it does return the data as I would expect. So I believe there's an issue with port 3000 / 8080. Port 3000 is where the client side of the application is served (I believe), which I figure is why Redux is doing the GET request to port :3000.
My question is, what can I do to resolve / debug this, so that my Redux fetches work once again? I assume that I simply need to "point" the Redux fetches to the right port, but I'm not sure how to do this.
Edit 1
Along the lines of this question, my client
file (with all of my front end code) is inside of the directory for my node API. In my client/package.json
file, I have a line with "proxy": "http://localhost:8080",
Edit 2
Here's the main function from teams-action
, which builds the URL that is then fetched:
export function fetchTeams(team, conference) {
return dispatch => {
let url = '/api/cbb/teams';
if (team) { url += '/team/' + team; }
else if (conference) { url += '/conference/' + conference; }
else { url += '/list'; }
console.log('fetchTeams url: ', url);
dispatch(fetchSportsDataBegin());
return fetch(url)
.then(handleErrors)
.then(res => res.json())
.then(json => {
dispatch(fetchSportsDataSuccess(json));
return json;
})
.catch(error => dispatch(fetchSportsDataError(error)));
};
}
fetchCBBTeams
is called from my main container component for the page. The url that is printed out is simply /api/cbb/teams/list
, since I am intentionally calling it with no parameters