Skip to content

Instantly share code, notes, and snippets.

@obrien-k
Forked from zprima/server.js
Created October 5, 2020 01:09
Show Gist options
  • Save obrien-k/d7e14fbe516752e600288b6b206511f8 to your computer and use it in GitHub Desktop.
Save obrien-k/d7e14fbe516752e600288b6b206511f8 to your computer and use it in GitHub Desktop.
medium_p1_c4
// Routes
app.get("/api/login", (req, res) => {
// generate a constant token, no need to be fancy here
const token = jwt.sign({ "username": "Mike" }, jwtSecret, { expiresIn: 60 }) // 1 min token
// return it back
res.json({ "token": token })
});
app.get("/api/token/ping", (req, res) => {
// Middleware will already catch if token is invalid
// so if he can get this far, that means token is valid
res.json({ "msg": "all good mate" })
})
app.get("/api/ping", (req, res) => {
// random endpoint so that the client can call something
res.json({ "msg": "pong" })
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment