Skip to content

Commit 6a8010d

Browse files
joelhooksleerobkodiakhq[bot]
authored
examples: Add inngest next.js example (#56049)
Co-authored-by: Lee Robinson <me@leerob.io> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent ee9a13a commit 6a8010d

File tree

12 files changed

+208
-1
lines changed

12 files changed

+208
-1
lines changed

docs/02-app/01-building-your-application/06-optimizing/10-third-party-libraries.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ docs](https://developers.google.com/maps/documentation/embed/embedding-map).
240240
| `allowfullscreen` | Optional | Property to allow certain map parts to go full screen. |
241241
| `loading` | Optional | Defaults to lazy. Consider changing if you know your embed will be above the fold. |
242242
| `q` | Optional | Defines map marker location. _This may be required depending on the map mode_. |
243-
| `center` | Optional | Defines the center of the map view. |
243+
| `center` | Optional | Defines the center of the map view. |
244244
| `zoom` | Optional | Sets initial zoom level of the map. |
245245
| `maptype` | Optional | Defines type of map tiles to load. |
246246
| `language` | Optional | Defines the language to use for UI elements and for the display of labels on map tiles. |

examples/inngest/.env.development

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
INNGEST_EVENT_KEY=your-event-key
2+
INNGEST_SIGNING_KEY=your-signing-key

examples/inngest/.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env*.local
29+
30+
# vercel
31+
.vercel
32+
33+
# typescript
34+
*.tsbuildinfo
35+
next-env.d.ts

examples/inngest/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Next.js and Inngest Example
2+
3+
This is an example of how to use [Inngest](https://inngest.com) to easily add durable work flows to your Next.js application. It keeps things simple:
4+
5+
- Bare bones examples with a single button UI that triggers an event
6+
- Runs the Inngest dev server locally for immediate feedback
7+
8+
## Deploy your own
9+
10+
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):
11+
12+
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/vercel/next.js/tree/canary/examples/inngest&project-name=inngest&repository-name=inngest)
13+
14+
To full deploy you'll need an [Inngest Cloud account](https://inngest.com) and the [Vercel Inngest integration](https://vercel.com/integrations/inngest) configured.
15+
16+
## How to use
17+
18+
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), [pnpm](https://pnpm.io), or [Bun](https://bun.sh/docs/cli/bunx) to bootstrap the example:
19+
20+
```bash
21+
npx create-next-app --example inngest inngest-app
22+
```
23+
24+
```bash
25+
yarn create next-app --example inngest inngest-app
26+
```
27+
28+
```bash
29+
pnpm create next-app --example inngest inngest-app
30+
```
31+
32+
```bash
33+
bunx create-next-app --example inngest inngest-app
34+
```
35+
36+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
37+
38+
## Notes
39+
40+
First, run the development server:
41+
42+
```bash
43+
npm run dev
44+
# or
45+
yarn dev
46+
# or
47+
pnpm dev
48+
# or
49+
bun dev
50+
```
51+
52+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
53+
54+
The Inngest dev server will be running at [http://localhost:8288](http://localhost:8288). It can take a few seconds to start up.

examples/inngest/next.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {}
3+
4+
module.exports = nextConfig

examples/inngest/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"dev": "concurrently \"npm:dev:*\"",
5+
"dev:next": "next dev",
6+
"dev:inngest": "npx inngest-cli@latest dev",
7+
"build": "next build",
8+
"start": "next start"
9+
},
10+
"dependencies": {
11+
"inngest": "^3.4.1",
12+
"next": "latest",
13+
"react": "18.2.0",
14+
"react-dom": "18.2.0"
15+
},
16+
"devDependencies": {
17+
"@types/node": "20.7.0",
18+
"@types/react": "18.2.23",
19+
"@types/react-dom": "18.2.7",
20+
"concurrently": "^8.2.1",
21+
"encoding": "^0.1.13",
22+
"typescript": "5.2.2"
23+
}
24+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { serve } from 'inngest/next'
2+
import { inngest } from '@/inngest/inngest.client'
3+
import { helloWorld } from '@/inngest/functions/hello-world'
4+
5+
export const { GET, POST, PUT } = serve(inngest, [helloWorld])
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { Metadata } from 'next'
2+
3+
export const metadata: Metadata = {
4+
title: 'Next.js Inngest Example',
5+
description: 'Generated by create next app',
6+
}
7+
8+
export default function RootLayout({
9+
children,
10+
}: {
11+
children: React.ReactNode
12+
}) {
13+
return (
14+
<html lang="en">
15+
<body>{children}</body>
16+
</html>
17+
)
18+
}

examples/inngest/src/app/page.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { inngest } from '@/inngest/inngest.client'
2+
import { redirect } from 'next/navigation'
3+
4+
export default function Home() {
5+
async function triggerInngestEvent() {
6+
'use server'
7+
await inngest.send({
8+
name: 'test/hello.world',
9+
data: {
10+
message: 'Hello from Next.js!',
11+
},
12+
})
13+
redirect('http://localhost:8288/stream')
14+
}
15+
return (
16+
<main>
17+
<div>
18+
<form action={triggerInngestEvent}>
19+
<button type="submit">Trigger Your Inngest Function</button>
20+
</form>
21+
</div>
22+
</main>
23+
)
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { inngest } from '../inngest.client'
2+
3+
export const helloWorld = inngest.createFunction(
4+
{ id: 'hello-world', name: 'Hello World' },
5+
{ event: 'test/hello.world' },
6+
async ({ event, step }) => {
7+
await step.sleep('sleep for a second', '1s')
8+
return { event, body: event.data.message }
9+
}
10+
)

0 commit comments

Comments
 (0)