Created
January 27, 2019 11:29
-
-
Save zprima/491a3706f9c33cd3b92ba1bb78919f00 to your computer and use it in GitHub Desktop.
medium_p1_c4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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