Solve CORS and more:

Add in server.js (in server side):

app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods','GET, POST, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type', 'Authorization');

next();
});

Add in client side:

When fetch is used in client side

GET
const url = 'http://localhost:8080/feed/posts'
fetch(url)
.then(res => res.json())
.then(resData => console.log(resData))
.catch(err => console.log(err));

POST
const url = 'http://localhost:8080/feed/post'
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
title: 'My new post',
content: 'My new content'
})
})
.then(res => res.json())
.then(resData => console.log(resData))
.catch(err => console.log(err));


Those are solving the following Error Message in the browser:

Access to fetch at < url > from origin 'https://cdpn.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.