import Koa from 'koa' ; export function withPrismicPreviewStatus ( ctx , next ) { const previewCookieName = 'isPreview' ; const isPreviewDomain = Boolean ( ctx . request . host . startsWith ( 'preview.' ) ) ; const previewCookieMatch = ctx . headers . cookie ? ctx . headers . cookie . match ( `(^|;) ?${ previewCookieName }=([^;]*)(;|$)` ) : undefined ; const previewCookie = previewCookieMatch ? previewCookieMatch [ 2 ] : undefined ; if ( isPreviewDomain && ! previewCookie ) { ctx . cookies . set ( 'isPreview' , 'true' , { httpOnly : false , } ) ; } return next ( ) ; }