Unverified Commit 658ffe2e authored by Joel Hooks's avatar Joel Hooks Committed by GitHub

examples: inngest example for latest version (#68600)

Co-authored-by: 's avatarmalewis5 <matthew.a.lewis7@gmail.com>
Co-authored-by: 's avatarLee Robinson <me@leerob.io>
parent f93c0bd3
CONTENTFUL_SPACE_ID= CONTENTFUL_SPACE_ID=
CONTENTFUL_ACCESS_TOKEN= CONTENTFUL_ACCESS_TOKEN=
CONTENTFUL_PREVIEW_ACCESS_TOKEN= CONTENTFUL_PREVIEW_ACCESS_TOKEN=
CONTENTFUL_PREVIEW_SECRET=
CONTENTFUL_REVALIDATE_SECRET= CONTENTFUL_REVALIDATE_SECRET=
\ No newline at end of file
import { draftMode } from "next/headers"; //@ts-ignore
import { redirect } from "next/navigation"; export { enableDraftHandler as GET } from "@contentful/vercel-nextjs-toolkit/app-router";
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}`);
}
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
"dependencies": { "dependencies": {
"@contentful/rich-text-react-renderer": "^15.17.1", "@contentful/rich-text-react-renderer": "^15.17.1",
"@contentful/rich-text-types": "^16.2.1", "@contentful/rich-text-types": "^16.2.1",
"@contentful/vercel-nextjs-toolkit": "latest",
"@tailwindcss/typography": "0.5.9", "@tailwindcss/typography": "0.5.9",
"@types/node": "^20.5.0", "@types/node": "^20.5.0",
"@types/react": "^18.2.20", "@types/react": "^18.2.20",
......
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "concurrently \"npm:dev:*\"", "dev": "concurrently \"npm:dev:*\"",
"dev:next": "next dev", "dev:next": "next dev --turbo",
"dev:inngest": "npx inngest-cli@latest dev", "dev:inngest": "inngest-cli dev --no-discovery -u http://localhost:3000/api/inngest",
"build": "next build", "build": "next build",
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"inngest": "latest", "inngest": "3.x",
"next": "latest", "next": "latest",
"react": "18.2.0", "react": "18.2.0",
"react-dom": "18.2.0" "react-dom": "18.2.0"
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
"@types/react-dom": "18.2.7", "@types/react-dom": "18.2.7",
"concurrently": "^8.2.1", "concurrently": "^8.2.1",
"encoding": "^0.1.13", "encoding": "^0.1.13",
"typescript": "5.2.2" "inngest-cli": "latest",
"typescript": "5.5.4"
} }
} }
import { inngestConfig } from "@/inngest/inngest.config";
import { serve } from "inngest/next"; 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);
import { inngest } from "@/inngest/inngest.client"; import { inngest } from "@/inngest/inngest.config";
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
export default function Home() { export default function Home() {
......
import { inngest } from "../inngest.client";
export 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 };
},
);
import { Inngest } from "inngest";
// Create a client to send and receive events
export const inngest = new Inngest({ id: "Basic Inngest Application" });
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],
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment