I feel like this should be a duplicate...If it is I'm not finding the correct thread.
I have an Express API (using mongoose) on a server with React front end. The API should return a JSON to the client.
Problem: It works fine with Postman but returns the wrong JSON in React
What I'm sending in Postman (this generates a correct response):
{"fileHashValue"
:
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}
Server Code:
app.get("/userData", function(req, res) {
const fileHashValue = req.body.fileHashValue;
UserData = UserData.findOne(
{
fileHashValue
},
function(err, userdata) {
res.json({
userdata
});
}
);
});
Client Code:
componentDidMount() {
axios
.get(
"http://ec2-52-53-190-3.us-west-1.compute.amazonaws.com:3000/userData",
{
fileHashValue:
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
}
)
.then(res => {
console.log(res.data);
});
}
It seems like this should all work, but its responding as if I had sent a blank request. IE, if I send a blank request in Postman it gives me the same result that I'm logging in React. Any help is appreciated, thanks!