README
🖼️ IPX
[!NOTE]
This is the active branch for IPX v2. Check out ipx/v1 for v1 docs.
Used by Nuxt Image and Netlify and open to everyone!
Using CLI
You can use ipx command to start server.
Using npx:
- ```bash
- npx ipx serve --dir ./
- ```
Usin bun
- ```bash
- bun x npx ipx serve --dir ./
- ```
The default serve directory is the current working directory.
Programatic API
You can use IPX as a middleware or directly use IPX interface.
- ```ts
- import { createIPX, ipxFSStorage, ipxHttpStorage } from "ipx";
- const ipx = createIPX({
- storage: ipxFSStorage({ dir: "./public" }),
- httpStorage: ipxHttpStorage({ domains: ["picsum.photos"] }),
- });
- ```
Example: Using with unjs/h3:
- ```js
- import { listen } from "listhen";
- import { createApp, toNodeListener } from "h3";
- import {
- createIPX,
- ipxFSStorage,
- ipxHttpStorage,
- createIPXH3Handler,
- } from "ipx";
- const ipx = createIPX({
- storage: ipxFSStorage({ dir: "./public" }),
- httpStorage: ipxHttpStorage({ domains: ["picsum.photos"] }),
- });
- const app = createApp().use("/", createIPXH3Handler(ipx));
- listen(toNodeListener(app));
- ```
Example: Using express:
- ```js
- import { listen } from "listhen";
- import express from "express";
- import {
- createIPX,
- ipxFSStorage,
- ipxHttpStorage,
- createIPXNodeServer,
- } from "ipx";
- const ipx = createIPX({
- storage: ipxFSStorage({ dir: "./public" }),
- httpStorage: ipxHttpStorage({ domains: ["picsum.photos"] }),
- });
- const app = express().use("/", createIPXNodeServer(ipx));
- listen(app);
- ```
URL Examples
Get original image:
/_/static/buffalo.png
Change format to webp and keep other things same as source:
/f_webp/static/buffalo.png
Keep original format (png) and set width to 200:
/w_200/static/buffalo.png
Resize to 200x200px using embed method and change format to webp:
/embed,f_webp,s_200x200/static/buffalo.png
Config
You can universally customize IPX configuration using IPX_* environment variables.
- IPX_ALIAS
- Default: {}
Filesystem Source Options
(enabled by default with CLI only)
IPX_FS_DIR
- Default: . (current working directory)
IPX_FS_MAX_AGE
- Default: 300
HTTP(s) Source Options
(enabled by default with CLI only)
IPX_HTTP_DOMAINS
- Default: []
IPX_HTTP_MAX_AGE
- Default: 300
IPX_HTTP_FETCH_OPTIONS
- Default: {}
IPX_HTTP_ALLOW_ALL_DOMAINS
- Default: false