Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add h3 middleware example #144

Merged
merged 5 commits into from
Sep 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,49 @@ The default server directory is the current working directory.

### Programatic Usage

You can use IPX as a Connect/Express middleware or directly use ipx api.
You can use IPX as a middleware or directly use ipx api.

#### H3 Middleware
[H3](https://github.com/unjs/h3) is a minimal h(ttp) framework built for high performance and portability. It is part of the [unjs](http://unjs.io) ecosystem to which `ipx` belongs.
atinux marked this conversation as resolved.
Show resolved Hide resolved

```js
import { createApp, eventHandler, toNodeListener } from "h3";
import { createIPX, createIPXMiddleware } from "ipx";
import { listen } from "listhen";

const app = createApp();
const ipx = createIPX({
domains: ['unjs.io']
});

const middleware = createIPXMiddleware(ipx)

const handler = eventHandler(async (event) => {
await middleware(event.node.req, event.node.res);
});

app.use("/image", handler);

listen(toNodeListener(app));
atinux marked this conversation as resolved.
Show resolved Hide resolved
```

#### Express Middleware
[Express](https://expressjs.com) is a fast, unopinionated, minimalist web framework for Node.js.

```js
import express from 'express';
import { createIPX, createIPXMiddleware } from "ipx";

const ipx = createIPX(/* options */);
const app = express();
const ipx = createIPX({
domains: ['unjs.io']
});

app.use("/image", createIPXMiddleware(ipx));

app.listen(3000, () =>
console.log('Example app listening on port 3000!'),
);
```

### Examples
Expand Down