From 87b5262c8dacbc83256200e6cabe47aa3023e2aa Mon Sep 17 00:00:00 2001 From: Matthew W Date: Tue, 29 Oct 2024 12:08:13 +1100 Subject: [PATCH] docs(recipes): add hapi example code --- docs/src/content/docs/reference/recipes.mdx | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/src/content/docs/reference/recipes.mdx b/docs/src/content/docs/reference/recipes.mdx index c8d797b..abe2799 100644 --- a/docs/src/content/docs/reference/recipes.mdx +++ b/docs/src/content/docs/reference/recipes.mdx @@ -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(); +```