Skip to content

Instantly share code, notes, and snippets.

@faresd
Created November 23, 2015 15:36
Show Gist options
  • Save faresd/9429ff5ab3d9ced4546d to your computer and use it in GitHub Desktop.
Save faresd/9429ff5ab3d9ced4546d to your computer and use it in GitHub Desktop.
Pages query
app.route('/:uid').get(function(req, res){
var uid = req.params['uid']
var p = prismic.withContext(req, res);
p.getByUID('page', uid, function(err, page) {
if(err) {
res.status(500)
.send("Error 500: " + err.message);
}
if(!page) {
res.status(404)
.send('Not found');
}
else if (page.uid == uid) {
res.render('page', {
page: page
})
} else res.redirect(("/" + page.uid))
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment