forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: inngest example for latest version (vercel#68600)
Co-authored-by: malewis5 <matthew.a.lewis7@gmail.com> Co-authored-by: Lee Robinson <me@leerob.io>
- Loading branch information
1 parent
f93c0bd
commit 658ffe2
Showing
9 changed files
with
44 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
CONTENTFUL_SPACE_ID= | ||
CONTENTFUL_ACCESS_TOKEN= | ||
CONTENTFUL_PREVIEW_ACCESS_TOKEN= | ||
CONTENTFUL_PREVIEW_SECRET= | ||
CONTENTFUL_REVALIDATE_SECRET= |
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 |
---|---|---|
@@ -1,22 +1,2 @@ | ||
import { draftMode } from "next/headers"; | ||
import { redirect } from "next/navigation"; | ||
import { getPreviewPostBySlug } from "../../../lib/api"; | ||
|
||
export async function GET(request: Request) { | ||
const { searchParams } = new URL(request.url); | ||
const secret = searchParams.get("secret"); | ||
const slug = searchParams.get("slug"); | ||
|
||
if (secret !== process.env.CONTENTFUL_PREVIEW_SECRET) { | ||
return new Response("Invalid token", { status: 401 }); | ||
} | ||
|
||
const post = await getPreviewPostBySlug(slug); | ||
|
||
if (!post) { | ||
return new Response("Invalid slug", { status: 401 }); | ||
} | ||
|
||
draftMode().enable(); | ||
redirect(`/posts/${post.slug}`); | ||
} | ||
//@ts-ignore | ||
export { enableDraftHandler as GET } from "@contentful/vercel-nextjs-toolkit/app-router"; |
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import { inngestConfig } from "@/inngest/inngest.config"; | ||
import { serve } from "inngest/next"; | ||
import { inngest } from "@/inngest/inngest.client"; | ||
import { helloWorld } from "@/inngest/functions/hello-world"; | ||
|
||
export const { GET, POST, PUT } = serve(inngest, [helloWorld]); | ||
export const { GET, POST, PUT } = serve(inngestConfig); |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,33 @@ | ||
import { EventSchemas, Inngest } from "inngest"; | ||
|
||
// TypeScript schema for the events | ||
export type Events = { | ||
"test/hello.world": { | ||
name: "test/hello.world"; | ||
data: { | ||
message: string; | ||
}; | ||
}; | ||
}; | ||
|
||
// Inngest client to send and receive events | ||
export const inngest = new Inngest({ | ||
id: "demo-app", | ||
schemas: new EventSchemas().fromRecord<Events>(), | ||
}); | ||
|
||
// a function to execute, typically in its own file | ||
const helloWorld = inngest.createFunction( | ||
{ id: "hello-world", name: "Hello World" }, | ||
{ event: "test/hello.world" }, | ||
async ({ event, step }) => { | ||
await step.sleep("sleep for a second", "1s"); | ||
return { event, body: event.data.message }; | ||
}, | ||
); | ||
|
||
// configuration for the Inngest api router | ||
export const inngestConfig = { | ||
client: inngest, | ||
functions: [helloWorld], | ||
}; |