My endpoint is localhost:8080/enquiry
and it returns the following JSON:
[{"_id":"5a283e4c5a36f4556af34742",
"firstName":"bob",
"surname":"hoskins",
"telephoneNumber":939483948,
"gender":"male",
"dayOfBirth":17,
"monthOfBirth":5,
"yearOfBirth":1978,"comments":"hello",
"emailAddress":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="046e6d696977767677446369656d682a6769">[email protected]</a>",
"createdAt":"2017-12-06T19:00:28.401Z"}]
The action creator I am using is:
export const receiveEnquiries = enquiries => ({
type: RECEIVE_ENQUIRIES,
enquiries
});
export const fetchEnquiries = () => dispatch => (
enquiryAPIUtil
.fetchEnquiries() // this is the fetch call in api.js below
.then((enquiries) => {dispatch(receiveEnquiries(enquiries))})
);
The fetch request in my api.js file looks like this:
export const fetchEnquiries = () =>
fetch(`${api}/enquiry`, { headers })
.then(res => {
res.json()
console.log("res",res)
})
.then(data => console.log("data",data))
Instead of logging the expected JSON, it logs:
res Response {type: "cors", url: "http://localhost:8080/enquiry",
redirected: false, status: 200, ok: true, …}
In my express server.js file, I have included:
const cors = require('cors')
app.use(cors())
as well as code to render the JSON data.
I'm trying to figure out if the issue lies on the client side or the server side?