mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Added preview functionality for home page
This commit is contained in:
27
app/api/preview/route.ts
Normal file
27
app/api/preview/route.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { draftMode } from 'next/headers'
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const secret = searchParams.get('secret')
|
||||
// const slug = searchParams.get('slug')
|
||||
const type = searchParams.get('type')
|
||||
const locale = searchParams.get('locale')
|
||||
|
||||
// Check the secret and next parameters
|
||||
// This secret should only be known to this route handler and the CMS
|
||||
if (secret !== process.env.SANITY_API_READ_TOKEN) {
|
||||
return new Response('Invalid token', { status: 401 })
|
||||
}
|
||||
|
||||
draftMode().enable()
|
||||
|
||||
|
||||
if (type === 'home') {
|
||||
return new Response(null, {
|
||||
status: 307,
|
||||
headers: {
|
||||
Location: `/${locale}`,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user