mirror of
https://github.com/vercel/commerce.git
synced 2025-05-14 13:47:49 +00:00
27 lines
720 B
TypeScript
27 lines
720 B
TypeScript
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}`,
|
|
},
|
|
})
|
|
}
|
|
} |