From 4d917ba9589b56c09b1462c3b5ab8eaf09b9c8b1 Mon Sep 17 00:00:00 2001 From: Luke Carr <24438483+lukecarr@users.noreply.github.com> Date: Wed, 12 Oct 2022 11:14:35 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=84=20Added=20Next.js,=20CF,=20and=20N?= =?UTF-8?q?etlify=20examples=20to=20README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luke Carr <24438483+lukecarr@users.noreply.github.com> --- README.md | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1aab61b..428bd59 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ console.log(mime); This is what the `Content-Type` header of the response supplied to `withError` is set to. -## ⚙ Options +## 🛠 Options You can supply options as an additional parameter to `withError` and `withTemplate` (and the subsequent `withError` function returned by the template) to configure Houston's behaviour: @@ -145,13 +145,36 @@ app.get("/not-found", (_, res) => { ### Next.js API Routes ```js -import { withError } from "@moducate/houston"; +import { withError } from "@moducate/houston/nextjs"; export default function handler(req, res) { - return withError(res, { type: "https://example.com/not-found", status: 404 }); + return withError(req, res, { type: "https://example.com/not-found", status: 404 }); } ``` +### Cloudflare Workers + +```js +import { withError } from "@moducate/houston/cf-workers"; + +addEventListener("fetch", event => { + return withError(event, { type: "https://example.com/not-found", status: 404 }); +}); +``` + +### Netlify Functions + +```ts +import { withError } from "@moducate/houston/netlify"; +import type { Handler } from "@netlify/functions"; + +const handler: Handler = async (event, context) => { + return withError(event, { type: "https://example.com/not-found", status: 404 }); +}; + +export { handler }; +``` + ### Fastify > ⚠ Fastify uses a custom `Reply` class, rather than `http.ServerResponse`.