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 all commits
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
53 changes: 41 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,60 @@

High performance, secure and easy to use image proxy based on [sharp](https://github.com/lovell/sharp) and [libvips](https://github.com/libvips/libvips).

## Usage

### Quick Start
## Using CLI

You can use `ipx` command to start server using:

```bash
$ npx ipx
npx ipx@latest
```

The default server directory is the current working directory.

### Programatic Usage
## Programatic API

You can use IPX as a middleware or directly use IPX interface.

You can use IPX as a Connect/Express middleware or directly use ipx api.
```ts
import { createIPX, createIPXMiddleware } from "ipx";

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

// (req, res) => void
const ipxMiddleware = createIPXMiddleware(ipx);
```

**Example**: Using with [unjs/h3](https://github.com/unjs/h3):

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

const ipx = createIPX({});
const ipxMiddleware = createIPXMiddleware(ipx);

const app = createApp().use("/", fromNodeMiddleware(ipxMiddleware));

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

**Example:** Using [express](https://expressjs.com):

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

const ipx = createIPX({});
const ipxMiddleware = createIPXMiddleware(ipx);

const app = express().use("/", ipxMiddleware);

const ipx = createIPX(/* options */);
const app = express();
app.use("/image", createIPXMiddleware(ipx));
listen(app);
```

### Examples
## Examples

Get original image:

Expand All @@ -47,7 +76,7 @@ Resize to `200x200px` using `embed` method and change format to `webp`:

`/embed,f_webp,s_200x200/static/buffalo.png`

### Modifiers
## Modifiers

| Property | Docs | Example | Comments |
| -------------- | :-------------------------------------------------------------- | :--------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -78,7 +107,7 @@ Resize to `200x200px` using `embed` method and change format to `webp`:
| grayscale | [Docs](https://sharp.pixelplumbing.com/api-colour#grayscale) | `/grayscale/buffalo.png` |
| animated | - | `/animated/buffalo.gif` | Experimental |

### Config
## Config

Config can be customized using `IPX_*` environment variables.

Expand Down