From 276912e7a21c039576013d2cfd2fc0f86a900cf6 Mon Sep 17 00:00:00 2001 From: Dan Farrelly Date: Tue, 3 Oct 2023 18:21:36 -0400 Subject: [PATCH] Default to Next.js app router in serve docs (#512) --- pages/docs/sdk/serve.mdx | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/pages/docs/sdk/serve.mdx b/pages/docs/sdk/serve.mdx index dc128d1b2..706ccd78a 100644 --- a/pages/docs/sdk/serve.mdx +++ b/pages/docs/sdk/serve.mdx @@ -220,31 +220,25 @@ See the [github.com/unjs/h3](https://github.com/unjs/h3) repository for more inf ## Framework: Next.js -Inngest has first class support for Next.js API routes, allowing you to easily create the Inngest API. -Add the following within `./pages/api/inngest.ts`: +Inngest has first class support for Next.js API routes, allowing you to easily create the Inngest API. Both the App Router and the Pages Router are supported. For the App Router, Inngest requires `GET`, `POST`, and `PUT` methods. - -```typescript -import { serve } from "inngest/next"; -import { inngest } from "../../inngest/client"; -import fnA from "../../inngest/fnA"; // Your own function - -export default serve(inngest, [fnA]); -``` - - -### Next.js 13+ - -Version 13+ of Next.js uses [Route Handlers](https://beta.nextjs.org/docs/routing/route-handlers), requiring a separate export for each HTTP method the API supports. Inngest requires `GET`, `POST`, and `PUT` methods (see [How the API works](#how-the-api-works) below), which you can export via destructuring instead of `export default`: - - -```typescript + +```typescript {{ title: "App Router" }} +// src/app/api/inngest/route.ts import { serve } from "inngest/next"; import { inngest } from "../../../inngest/client"; import fnA from "../../../inngest/fnA"; // Your own functions export const { GET, POST, PUT } = serve(inngest, [fnA]); ``` +```typescript {{ title: "Pages Router" }} +// pages/api/inngest.ts +import { serve } from "inngest/next"; +import { inngest } from "../../inngest/client"; +import fnA from "../../inngest/fnA"; // Your own function + +export default serve(inngest, [fnA]); +``` ### Streaming