I am trying to create a small application that allows the user to return data from the GitHub API, I have a React application that gets its data from an express server.
When I call the express path from Postman the data is returned okay so I don't believe the call itself to be the issue.
app.js
app.post("/GHIssueBeautifier/issues", (req, res) => {
const { repo } = req.body;
dotenv.config();
fetch(`https://api.github.com/repos/ORGNAME/${repo}/issues`, {
headers: {
Authorization: `token ${process.env.PERSONAL_ACCESS_TOKEN}`,
},
method: "GET"
})
.then((response) => response.json())
.then((response) => {
return res.status(200).json(response);
})
.catch((error) => {
return res.status(400).json(error);
});
});
I have used console.logs to check that the data is returned correctly and it looks like it is.
Home.js
const searchRepo = () => {
const requestData = {
repo: this.state.repo,
};
fetch(`${process.env.REACT_APP_API_URL}GHIssueBeautifier/issues`, {
method: "POST",
body: JSON.stringify(requestData)
})
.then((response) => {
response.json()
})
.then((data) => {
data.forEach(element => {
element.milestone_search = this.state.milestone
});
this.setState({ items: data });
})
.catch((error) => {
console.log('Error', error);
});
};
This fetch always return the error:
The network tools in Chrome show me that the request has been cancelled:
Any help is greatly appreciated.