Last active
April 10, 2018 14:25
-
-
Save unr/242849ec09e7970e871657717d1f2192 to your computer and use it in GitHub Desktop.
.vue route for /preview
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
<template> | |
<div>loading preview...</div> | |
</template> | |
<script> | |
import prismic from 'prismic-javascript'; | |
import LinkResolver from '~/functions/LinkResolver'; | |
export default { | |
name: 'prismicpreview', | |
layout: 'empty', | |
head() { | |
return { | |
title: 'loading preview...', | |
}; | |
}, | |
async fetch({ env, redirect, query }) { | |
// if token isn't passed, dead url, redirect to / | |
const token = query.token; | |
if (!token) redirect('/'); | |
console.log(token); | |
// ctx.api.previewSession(previewToken, ctx.linkResolver, '/', function(err, redirectUrl) { | |
// res.cookie(Prismic.previewCookie, previewToken, { maxAge: 60 * 30 * 1000, path: '/', httpOnly: false }); | |
// res.redirect(redirectUrl); | |
// }); | |
const api = await prismic.getApi(env.prismicApi); | |
const tokenQuery = await api.query( | |
prismic.Predicates.at('document.type', 'blog-post'), | |
{ ref : token } | |
); | |
console.log(tokenQuery); | |
await api.previewSession(token, LinkResolver, '/', (err, url) => { | |
console.log(err); | |
console.log(url); | |
}); | |
}, | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment