Hey there, hope everyone is having a great night! I just got caught up in something for about an hour and a half, so I apologize in advance for taking up your time with this question.
So, I'm trying to retrieve the posts from: http://localhost:5000/posts
When I use the following code:
fetch('/posts')
.then(res => res.json())
.then(resBody => console.log(resBody));
In the Firefox Developer Console, I receive the following error:
Content Security Policy: The page's settings blocked the loading of a resource at http://localhost:5000/posts ("default-src").
Promise { <state>: "rejected", <reason>: TypeError }
<state>: "rejected"
<reason>: TypeError: NetworkError when attempting to fetch resource.
<prototype>: Promise.prototype { … }
Using Postman, I am able to fetch the array of JSON objects (The Posts)
[{"postId":1,"message":"Hello World!"},{"postId":2,"message":"Ciao!"}]
I can successfully make POST requests and add new posts to the server using Postman.
The issue arises when I try to do the same in the developer console using Firefox.
I don't believe it's related to the server code (since Postman works fine), but here is the server code in case you want to test it:
const posts = [
{
postId: 1,
message: "Hello World!"
},
{
postId: 2,
message: "Ciao!"
},
];
let nextPostId = 3;
// Continued server code...