Can anyone point out where the problem is?, just working through JWT and the server is just hanging with no information being sent

Viewed 21

server.js file

creating the array and posting username and title

const posts = [
  {
    username: "liam",
    title: "Post 1",
  },
  {
    username: "phil",
    title: "Post 2",
  },
];

Routes and requests have been created below

app.get("/posts", (req, res) => {
  res.json(posts);
});
app.post("/login", (req, res) => {
  // auth
  const username = req.body.username;
  const user = { name: username };

  const accessToken = jwt.sign(user, process.env.ACCESS_TOKEN_SECRET);
  res.json({ accessToken: accessToken });
});

app.listen(5000);

**.rest file for requests **

get and post requests to server

GET http://localhost:5000/posts


###

POST http://localhost:5000/login
Content-Type: application/json

{
    "username": "liam"
}
0 Answers
Related