Skip to content

Commit

Permalink
πŸ“„ Added Next.js, CF, and Netlify examples to README
Browse files Browse the repository at this point in the history
Signed-off-by: Luke Carr <[email protected]>
  • Loading branch information
lukecarr authored Oct 12, 2022
1 parent d2043cb commit 4d917ba
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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`.
Expand Down

0 comments on commit 4d917ba

Please sign in to comment.