ipx 0.9.7 → 0.9.10

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.
@@ -120,18 +120,23 @@ function isValidPath(fp) {
120
120
  const createHTTPSource = (options) => {
121
121
  const httpsAgent = new https__default.Agent({ keepAlive: true });
122
122
  const httpAgent = new http__default.Agent({ keepAlive: true });
123
- let domains = options.domains || [];
124
- if (typeof domains === "string") {
125
- domains = domains.split(",").map((s) => s.trim());
123
+ let _domains = options.domains || [];
124
+ if (typeof _domains === "string") {
125
+ _domains = _domains.split(",").map((s) => s.trim());
126
126
  }
127
- const hosts = domains.map((domain) => ufo.parseURL(domain, "https://").host);
127
+ const domains = _domains.map((d) => {
128
+ if (!d.startsWith("http")) {
129
+ d = "http://" + d;
130
+ }
131
+ return new URL(d).hostname;
132
+ }).filter(Boolean);
128
133
  return async (id, reqOptions) => {
129
- const url = new URL(id);
130
- if (!url.hostname) {
134
+ const hostname = new URL(id).hostname;
135
+ if (!hostname) {
131
136
  throw createError("Hostname is missing", 403, id);
132
137
  }
133
- if (!reqOptions?.bypassDomain && !hosts.find((host) => url.hostname === host)) {
134
- throw createError("Forbidden host", 403, url.hostname);
138
+ if (!reqOptions?.bypassDomain && !domains.find((domain) => hostname === domain)) {
139
+ throw createError("Forbidden host", 403, hostname);
135
140
  }
136
141
  const response = await ohmyfetch.fetch(id, {
137
142
  agent: id.startsWith("https") ? httpsAgent : httpAgent,
@@ -555,7 +560,7 @@ function handleRequest(req, ipx) {
555
560
  }
556
561
  function createIPXMiddleware(ipx) {
557
562
  return function IPXMiddleware(req, res) {
558
- handleRequest({ url: req.url, headers: req.headers }, ipx).then((_res) => {
563
+ return handleRequest({ url: req.url, headers: req.headers }, ipx).then((_res) => {
559
564
  res.statusCode = _res.statusCode;
560
565
  res.statusMessage = _res.statusMessage;
561
566
  for (const name in _res.headers) {
@@ -1,6 +1,6 @@
1
1
  import defu from 'defu';
2
2
  import { imageMeta } from 'image-meta';
3
- import { parseURL, withLeadingSlash, hasProtocol, joinURL, decode } from 'ufo';
3
+ import { withLeadingSlash, hasProtocol, joinURL, decode } from 'ufo';
4
4
  import { promises } from 'fs';
5
5
  import { resolve, join, parse } from 'pathe';
6
6
  import http from 'http';
@@ -109,18 +109,23 @@ function isValidPath(fp) {
109
109
  const createHTTPSource = (options) => {
110
110
  const httpsAgent = new https.Agent({ keepAlive: true });
111
111
  const httpAgent = new http.Agent({ keepAlive: true });
112
- let domains = options.domains || [];
113
- if (typeof domains === "string") {
114
- domains = domains.split(",").map((s) => s.trim());
112
+ let _domains = options.domains || [];
113
+ if (typeof _domains === "string") {
114
+ _domains = _domains.split(",").map((s) => s.trim());
115
115
  }
116
- const hosts = domains.map((domain) => parseURL(domain, "https://").host);
116
+ const domains = _domains.map((d) => {
117
+ if (!d.startsWith("http")) {
118
+ d = "http://" + d;
119
+ }
120
+ return new URL(d).hostname;
121
+ }).filter(Boolean);
117
122
  return async (id, reqOptions) => {
118
- const url = new URL(id);
119
- if (!url.hostname) {
123
+ const hostname = new URL(id).hostname;
124
+ if (!hostname) {
120
125
  throw createError("Hostname is missing", 403, id);
121
126
  }
122
- if (!reqOptions?.bypassDomain && !hosts.find((host) => url.hostname === host)) {
123
- throw createError("Forbidden host", 403, url.hostname);
127
+ if (!reqOptions?.bypassDomain && !domains.find((domain) => hostname === domain)) {
128
+ throw createError("Forbidden host", 403, hostname);
124
129
  }
125
130
  const response = await fetch(id, {
126
131
  agent: id.startsWith("https") ? httpsAgent : httpAgent,
@@ -544,7 +549,7 @@ function handleRequest(req, ipx) {
544
549
  }
545
550
  function createIPXMiddleware(ipx) {
546
551
  return function IPXMiddleware(req, res) {
547
- handleRequest({ url: req.url, headers: req.headers }, ipx).then((_res) => {
552
+ return handleRequest({ url: req.url, headers: req.headers }, ipx).then((_res) => {
548
553
  res.statusCode = _res.statusCode;
549
554
  res.statusMessage = _res.statusMessage;
550
555
  for (const name in _res.headers) {
package/dist/index.d.ts CHANGED
@@ -49,6 +49,6 @@ interface IPXHResponse {
49
49
  body: any;
50
50
  }
51
51
  declare function handleRequest(req: IPXHRequest, ipx: IPX): Promise<IPXHResponse>;
52
- declare function createIPXMiddleware(ipx: IPX): (req: IncomingMessage, res: ServerResponse) => void;
52
+ declare function createIPXMiddleware(ipx: IPX): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
53
53
 
54
54
  export { IPX, IPXCTX, IPXHRequest, IPXHResponse, IPXOptions, ImageMeta, Source, SourceData, SourceFactory, createIPX, createIPXMiddleware, handleRequest };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ipx",
3
- "version": "0.9.7",
3
+ "version": "0.9.10",
4
4
  "repository": "unjs/ipx",
5
5
  "license": "MIT",
6
6
  "exports": {
@@ -25,9 +25,9 @@
25
25
  "image-meta": "^0.1.1",
26
26
  "listhen": "^0.2.13",
27
27
  "ohmyfetch": "^0.4.18",
28
- "pathe": "^0.3.0",
28
+ "pathe": "^0.3.2",
29
29
  "sharp": "^0.30.7",
30
- "ufo": "^0.8.4",
30
+ "ufo": "^0.8.5",
31
31
  "xss": "^1.0.13"
32
32
  },
33
33
  "devDependencies": {
@@ -46,7 +46,7 @@
46
46
  "unbuild": "latest",
47
47
  "vitest": "latest"
48
48
  },
49
- "packageManager": "pnpm@7.3.0",
49
+ "packageManager": "pnpm@7.5.0",
50
50
  "scripts": {
51
51
  "build": "unbuild",
52
52
  "dev": "nodemon",