-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from strapi/feat/preview-2
add: preview
- Loading branch information
Showing
18 changed files
with
476 additions
and
187 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { draftMode } from 'next/headers' | ||
import { redirect } from 'next/navigation' | ||
|
||
export const GET = async (request: Request) => { | ||
|
||
const { searchParams } = new URL(request.url) | ||
const secret = searchParams.get('secret') | ||
const slug = searchParams.get('slug') | ||
const locale = searchParams.get('locale') | ||
const uid = searchParams.get('uid') | ||
const status = searchParams.get('status'); | ||
|
||
if ( | ||
secret !== process.env.PREVIEW_SECRET | ||
) { | ||
return new Response('Invalid token', { status: 401 }) | ||
} | ||
|
||
const contentType = uid?.split(".").pop(); | ||
|
||
// Specific for the application | ||
let slugToReturn = `/${locale}/${contentType}`; | ||
|
||
if (contentType === 'page' || contentType === 'global') { | ||
if (slug && slug !== 'homepage') { | ||
slugToReturn = `/${locale}/${slug}`; | ||
} else { | ||
slugToReturn = `/${locale}`; | ||
} | ||
} else if (contentType === 'article' || contentType?.includes('blog')) { | ||
slugToReturn = `/${locale}/blog${slug ? `/${slug}` : ''}`; | ||
} else if (contentType?.includes('product')) { | ||
slugToReturn = `/en/products${slug ? `/${slug}` : ''}`; | ||
} | ||
|
||
const draft = await draftMode() | ||
if (status === 'draft') { | ||
draft.enable() | ||
} else { | ||
draft.disable() | ||
} | ||
redirect(slugToReturn) | ||
}; |
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
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
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
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
Oops, something went wrong.