ipx 1.3.0 → 2.0.0-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,28 +3,48 @@
3
3
  [![npm version][npm-version-src]][npm-version-href]
4
4
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
5
 
6
- High performance, secure and easy to use image proxy based on [sharp](https://github.com/lovell/sharp) and [libvips](https://github.com/libvips/libvips).
6
+ High performance, secure and easy-to-use image optimizer.
7
+
8
+ Powered by [sharp](https://github.com/lovell/sharp) and [libvips](https://github.com/libvips/libvips).
9
+
10
+ > [!IMPORTANT]
11
+ > This is the development branch for IPX v2. Check out [ipx/v1](https://github.com/unjs/ipx/tree/v1) for latest stable docs and [#71](https://github.com/unjs/ipx/issues/171) for v2 roadmap.
7
12
 
8
13
  ## Using CLI
9
14
 
10
- You can use `ipx` command to start server using:
15
+ You can use `ipx` command to start server.
16
+
17
+ Using `npx`:
18
+
19
+ ```bash
20
+ npx ipx@next-2 serve --dir ./
21
+ ```
22
+
23
+ Usin `bun`
11
24
 
12
25
  ```bash
13
- npx ipx@latest
26
+ bun x npx ipx@next-2 serve --dir ./
14
27
  ```
15
28
 
16
- The default server directory is the current working directory.
29
+ The default serve directory is the current working directory.
17
30
 
18
31
  ## Programatic API
19
32
 
20
33
  You can use IPX as a middleware or directly use IPX interface.
21
34
 
22
35
  ```ts
23
- import { createIPX, createIPXMiddleware } from "ipx";
24
-
25
- const ipx = createIPX({ domains: ["unjs.io"] });
36
+ import {
37
+ createIPX,
38
+ createIPXMiddleware,
39
+ ipxFSStorage,
40
+ ipxHttpStorage,
41
+ } from "ipx";
42
+
43
+ const ipx = createIPX({
44
+ storage: ipxFSStorage({ dir: "./public" }),
45
+ httpStorage: ipxHttpStorage({ domains: ["picsum.photos"] }),
46
+ });
26
47
 
27
- // (req, res) => void
28
48
  const ipxMiddleware = createIPXMiddleware(ipx);
29
49
  ```
30
50
 
@@ -33,10 +53,6 @@ const ipxMiddleware = createIPXMiddleware(ipx);
33
53
  ```js
34
54
  import { createIPX, createIPXMiddleware } from "ipx";
35
55
  import { listen } from "listhen";
36
- import { createApp, fromNodeMiddleware, toNodeListener } from "h3";
37
-
38
- const ipx = createIPX({});
39
- const ipxMiddleware = createIPXMiddleware(ipx);
40
56
 
41
57
  const app = createApp().use("/", fromNodeMiddleware(ipxMiddleware));
42
58
 
@@ -46,19 +62,15 @@ listen(toNodeListener(app));
46
62
  **Example:** Using [express](https://expressjs.com):
47
63
 
48
64
  ```js
49
- import { createIPX, createIPXMiddleware } from "ipx";
50
65
  import { listen } from "listhen";
51
66
  import express from "express";
52
67
 
53
- const ipx = createIPX({});
54
- const ipxMiddleware = createIPXMiddleware(ipx);
55
-
56
68
  const app = express().use("/", ipxMiddleware);
57
69
 
58
70
  listen(app);
59
71
  ```
60
72
 
61
- ## Examples
73
+ ## URL Examples
62
74
 
63
75
  Get original image:
64
76
 
@@ -76,6 +88,46 @@ Resize to `200x200px` using `embed` method and change format to `webp`:
76
88
 
77
89
  `/embed,f_webp,s_200x200/static/buffalo.png`
78
90
 
91
+ ## Config
92
+
93
+ You can universally customize IPX configuration using `IPX_*` environment variables.
94
+
95
+ - `IPX_ALIAS`
96
+
97
+ - Default: `{}`
98
+
99
+ ### Filesystem Source Options
100
+
101
+ (enabled by default with CLI only)
102
+
103
+ #### `IPX_FS_DIR`
104
+
105
+ - Default: `.` (current working directory)
106
+
107
+ #### `IPX_FS_MAX_AGE`
108
+
109
+ - Default: `300`
110
+
111
+ ### HTTP(s) Source Options
112
+
113
+ (enabled by default with CLI only)
114
+
115
+ #### `IPX_HTTP_DOMAINS`
116
+
117
+ - Default: `[]`
118
+
119
+ #### `IPX_HTTP_MAX_AGE`
120
+
121
+ - Default: `300`
122
+
123
+ #### `IPX_HTTP_FETCH_OPTIONS`
124
+
125
+ - Default: `{}`
126
+
127
+ #### `IPX_HTTP_ALLOW_ALL_DOMAINS`
128
+
129
+ - Default: `false`
130
+
79
131
  ## Modifiers
80
132
 
81
133
  | Property | Docs | Example | Comments |
@@ -107,30 +159,6 @@ Resize to `200x200px` using `embed` method and change format to `webp`:
107
159
  | grayscale | [Docs](https://sharp.pixelplumbing.com/api-colour#grayscale) | `/grayscale/buffalo.png` |
108
160
  | animated | - | `/animated/buffalo.gif` | Experimental |
109
161
 
110
- ## Config
111
-
112
- Config can be customized using `IPX_*` environment variables.
113
-
114
- - `IPX_DIR`
115
-
116
- - Default: `.` (current working directory)
117
-
118
- - `IPX_DOMAINS`
119
-
120
- - Default: `[]`
121
-
122
- - `IPX_MAX_AGE`
123
-
124
- - Default: `300`
125
-
126
- - `IPX_ALIAS`
127
-
128
- - Default: `{}`
129
-
130
- - `IPX_FETCH_OPTIONS`
131
-
132
- - Default: `{}`
133
-
134
162
  ## License
135
163
 
136
164
  [MIT](./LICENSE)
package/dist/cli.cjs CHANGED
@@ -1,33 +1,63 @@
1
1
  'use strict';
2
2
 
3
- const consola = require('consola');
4
3
  const listhen = require('listhen');
5
- const index = require('./index.cjs');
4
+ const citty = require('citty');
5
+ const cli = require('listhen/cli');
6
+ const nodeFs = require('./shared/ipx.680a50a5.cjs');
6
7
  require('defu');
7
8
  require('image-meta');
8
9
  require('ufo');
9
- require('node:fs');
10
- require('pathe');
10
+ require('h3');
11
11
  require('destr');
12
- require('node:http');
13
- require('node:https');
14
- require('node-fetch-native');
15
12
  require('@fastify/accept-negotiator');
16
13
  require('etag');
17
- require('xss');
18
-
19
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
14
+ require('ofetch');
15
+ require('pathe');
20
16
 
21
- const consola__default = /*#__PURE__*/_interopDefaultCompat(consola);
17
+ const name = "ipx";
18
+ const version = "2.0.0-1";
19
+ const description = "High performance, secure and easy-to-use image optimizer.";
22
20
 
23
- async function main() {
24
- const ipx = index.createIPX({});
25
- const middleware = index.createIPXMiddleware(ipx);
26
- await listhen.listen(middleware, {
27
- clipboard: false
28
- });
29
- }
30
- main().catch((error) => {
31
- consola__default.error(error);
32
- process.exit(1);
21
+ const serve = citty.defineCommand({
22
+ meta: {
23
+ description: "Start IPX Server"
24
+ },
25
+ args: {
26
+ dir: {
27
+ type: "string",
28
+ required: false,
29
+ description: "Directory to serve (default: current directory) ENV: IPX_FS_DIR"
30
+ },
31
+ domains: {
32
+ type: "string",
33
+ required: false,
34
+ description: "Allowed domains (comma separated) ENV: IPX_HTTP_DOMAINS"
35
+ },
36
+ ...cli.getArgs()
37
+ },
38
+ async run({ args }) {
39
+ const ipx = nodeFs.createIPX({
40
+ storage: nodeFs.ipxFSStorage({
41
+ dir: args.dir
42
+ }),
43
+ httpStorage: nodeFs.ipxHttpStorage({
44
+ domains: args.domains
45
+ })
46
+ });
47
+ await listhen.listen(nodeFs.createIPXNodeServer(ipx), {
48
+ name: "IPX",
49
+ ...cli.parseArgs(args)
50
+ });
51
+ }
52
+ });
53
+ const main = citty.defineCommand({
54
+ meta: {
55
+ name,
56
+ version,
57
+ description
58
+ },
59
+ subCommands: {
60
+ serve
61
+ }
33
62
  });
63
+ citty.runMain(main);
package/dist/cli.mjs CHANGED
@@ -1,27 +1,61 @@
1
- import consola from 'consola';
2
1
  import { listen } from 'listhen';
3
- import { createIPX, createIPXMiddleware } from './index.mjs';
2
+ import { defineCommand, runMain } from 'citty';
3
+ import { getArgs, parseArgs } from 'listhen/cli';
4
+ import { c as createIPX, g as ipxFSStorage, i as ipxHttpStorage, e as createIPXNodeServer } from './shared/ipx.57fad794.mjs';
4
5
  import 'defu';
5
6
  import 'image-meta';
6
7
  import 'ufo';
7
- import 'node:fs';
8
- import 'pathe';
8
+ import 'h3';
9
9
  import 'destr';
10
- import 'node:http';
11
- import 'node:https';
12
- import 'node-fetch-native';
13
10
  import '@fastify/accept-negotiator';
14
11
  import 'etag';
15
- import 'xss';
12
+ import 'ofetch';
13
+ import 'pathe';
16
14
 
17
- async function main() {
18
- const ipx = createIPX({});
19
- const middleware = createIPXMiddleware(ipx);
20
- await listen(middleware, {
21
- clipboard: false
22
- });
23
- }
24
- main().catch((error) => {
25
- consola.error(error);
26
- process.exit(1);
15
+ const name = "ipx";
16
+ const version = "2.0.0-1";
17
+ const description = "High performance, secure and easy-to-use image optimizer.";
18
+
19
+ const serve = defineCommand({
20
+ meta: {
21
+ description: "Start IPX Server"
22
+ },
23
+ args: {
24
+ dir: {
25
+ type: "string",
26
+ required: false,
27
+ description: "Directory to serve (default: current directory) ENV: IPX_FS_DIR"
28
+ },
29
+ domains: {
30
+ type: "string",
31
+ required: false,
32
+ description: "Allowed domains (comma separated) ENV: IPX_HTTP_DOMAINS"
33
+ },
34
+ ...getArgs()
35
+ },
36
+ async run({ args }) {
37
+ const ipx = createIPX({
38
+ storage: ipxFSStorage({
39
+ dir: args.dir
40
+ }),
41
+ httpStorage: ipxHttpStorage({
42
+ domains: args.domains
43
+ })
44
+ });
45
+ await listen(createIPXNodeServer(ipx), {
46
+ name: "IPX",
47
+ ...parseArgs(args)
48
+ });
49
+ }
50
+ });
51
+ const main = defineCommand({
52
+ meta: {
53
+ name,
54
+ version,
55
+ description
56
+ },
57
+ subCommands: {
58
+ serve
59
+ }
27
60
  });
61
+ runMain(main);