Reputation: 1427
I'm working on a game, i'm trying to get the client to post/put data about the player to the server, but after 6 requests the server seems to crash, then after a minute or so it will accept another 6 requests and repeat. This is the post code:
app.post('/entityData', function(req, res) {
//test = req.body;
//console.log(test);
console.log(req.body);
//entityList[req.params.uid] = req.body;
});
I've got a fair amount of other code but these are all for get requests, which seem to work fine with the client. Here is the code my client is sending:
async function sendPlayerData() {
let playerData = {
num: player.getPos().x
};
console.log(playerData);
try {
let response = await fetch(serverIP + "/entityData", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(playerData)
});
if(!response.ok) {
throw new Error("Error sending player data to server. ");
}
} catch (error) {
console.log(error);
}
}
I get no errors on the client or server, so have absolutely no idea what i'm doing wrong. The only modules i've got on the server is a custom utility module and fs.
Upvotes: 1
Views: 552
Reputation: 1427
The issue was that i was not sending back a response, after i fixed that it worked.
Upvotes: 3