Skip to content

Commit

Permalink
docs(recipes): add hapi example code
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewWid committed Oct 29, 2024
1 parent 45f251a commit 87b5262
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions docs/src/content/docs/reference/recipes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,33 @@ router.get("/sse", async ({ request, response }) => {
session.push("Hello world!");
});
```

### [Hapi](https://hapi.dev/)

```typescript title="server.ts"
import Hapi from "@hapi/hapi";
import { createSession } from "better-sse";

const init = async () => {
const server = Hapi.server({
port: 8080,
host: "localhost",
});

server.route({
method: "GET",
path: "/sse",
handler: async ({ raw }, { abandon }) => {
const session = await createSession(raw.req, raw.res);

session.push("Hello world!");

return abandon;
},
});

await server.start();
};

init();
```

0 comments on commit 87b5262

Please sign in to comment.