I'm fairly new to web development and I'm trying to send some JSON data to a node.js server running express but I'm getting this error:
Failed to load http://localhost:8888/: Method PUT is not allowed by Access-Control-Allow-Methods in preflight response.
I have no idea what this means. This is the client-side fetch:
fetch('http://localhost:8888/', {
method: 'PUT',
body: JSON.stringify(this.exercises),
headers: {
'Content-Type': 'application/json'
}
}).then(res => res.json())
.catch(err => console.error('Error: ' + err))
.then(res => console.log('Success: ' + res));
And this is the server-side code:
app.put('/', (req, res, next) => {
console.log('PUT request received');
console.log(req.body);
});
The server doesn't even seem to receive the request. How do I make this work? Thanks in advance.