Reputation: 887
I'm attempting to fetch data on my server using the fetch API for the request, but the request is taking FOREVER to process (it does eventually process). I'm using React as my view, and Express is serving up my pages. I've listed my Express and JSX code below. Any insight into why this may be happening (The 'mounted' message is logged immediately as expected, but the fetch API after delays) ?
Express:
app.use('/test',function(){
console.log('connected');
})
React.JS:
componentDidMount(){
console.log('mounted');
fetch('./test').then(function(response){
console.log(response);
}).catch(function(error){
console.log(error);
})
}
Upvotes: 1
Views: 2570
Reputation: 93531
You have to send the response in the server side :
app.use('/test',function(request, response){
console.log('connected');
response.send(); //!!!!! this line
//Or: response.sendStatus(200); to send status code without body
});
... otherwise the endpoint will not be terminated.
Upvotes: 5