app.get('/categories', (req, res) => { categories.getAll(req.token) .then( (data) => res.send(data), (error) => { console.error(error) res.status(500).send({ error: 'There was an error.' }) } ) })
app.post('/api/post', verifyToken, (req,res) => { jwt.verify(req.token,"cokelek", (err,authData) => { if(err){ res.sendStatus(403); } res.json({ message: "Post created.", authData }); }); });
app.put('/comments/:id', bodyParser.json(), (req, res) => { comments.edit(req.token, req.params.id, req.body) .then( (data) => res.send(data), (error) => { console.error(error) res.status(500).send({ error: 'There was an error.' }) } ) })
//logout app.delete('/users/me/token', authenticate, (req, res) => { req.user.removeToken(req.token).then(() => { res.status(200).send(); }, () => { res.status(400).send(); }); });
app.get('/:category/posts', (req, res) => { posts.getByCategory(req.token, req.params.category) .then( (data) => res.send(data), (error) => { console.error(error) res.status(500).send({ error: 'There was an error.' }) } ) })
app.post('/comments', bodyParser.json(), (req, res) => { comments.add(req.token, req.body) .then( (data) => res.send(data), (error) => { console.error(error) res.status(500).send({ error: 'There was an error.' }) } ) })
// Logout user from JWT router.get('/logout', isTokenValid, function (req, res) { // We filter the variables to get ride of the bad one activeTokens[req.token["decoded"]["username"]] = activeTokens[req.token["decoded"]["username"]].filter(function (value) { return value.token != req.token["token"]; }) res.status(200).send(true); });
router.post('/api/posts', verifyToken, (req, res) => { jwt.verify(req.token, 'secretkey', (err, authData) => { if (err) { res.json({ message: "authentication error..." }) } else { res.json({ message: "post created...", authData }) } }) })
app.get('/posts/:id', (req, res) => { posts.get(req.token, req.params.id) .then( (data) => res.send(data), (error) => { console.error(error) res.status(500).send({ error: 'There was an error.' }) } ) })
app.get('/posts/:id/comments', (req, res) => { comments.getByParent(req.token, req.params.id) .then( (data) => res.send(data), (error) => { console.error(error) res.status(500).send({ error: 'There was an error.' }) } ) })
app.get('/posts', (req, res) => { posts.getAll(req.token) .then( (data) => res.send(data), (error) => { console.error(error) res.status(500).send({ error: 'There was an error.' }) } ) })
app.put('/posts/:id', bodyParser.json(), (req, res) => { posts.edit(req.token, req.params.id, req.body) .then( (data) => res.send(data), (error) => { console.error(error) res.status(500).send({ error: 'There was an error.' }) } ) })
// Logout user from JWT router.get('/logout', isTokenValid, function (req, res) { // We filter the variables to get ride of the bad one activeTokens[req.token["decoded"]["username"]] = activeTokens[req.token["decoded"]["username"]].filter(function (value) { return value.token != req.token["token"]; }) res.status(200).send(true); });
app.post('/api/posts', verifyToken, (req, res) => { jwt.verify(req.token, 'secretkey', (err, authData) => { if (err) { res.sendStatus(403); } else { res.json({ message: 'Post created...', authData }); } }) });
app.post('/api/posts', verifyToken, (req, res) => { jwt.verify(req.token, 'secretkey', (err, authData) => { if(err) { res.sendStatus(403); } else { res.json({ message: 'Post created...', authData }); } }); });