ipx 0.9.7 → 0.9.8

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,18 @@ 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) => new URL(d).hostname || new URL("http://" + d).hostname).filter(Boolean);
128
128
  return async (id, reqOptions) => {
129
- const url = new URL(id);
130
- if (!url.hostname) {
129
+ const hostname = new URL(id).hostname;
130
+ if (!hostname) {
131
131
  throw createError("Hostname is missing", 403, id);
132
132
  }
133
- if (!reqOptions?.bypassDomain && !hosts.find((host) => url.hostname === host)) {
134
- throw createError("Forbidden host", 403, url.hostname);
133
+ if (!reqOptions?.bypassDomain && !domains.find((domain) => hostname === domain)) {
134
+ throw createError("Forbidden host", 403, hostname);
135
135
  }
136
136
  const response = await ohmyfetch.fetch(id, {
137
137
  agent: id.startsWith("https") ? httpsAgent : httpAgent,
@@ -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,18 @@ 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) => new URL(d).hostname || new URL("http://" + d).hostname).filter(Boolean);
117
117
  return async (id, reqOptions) => {
118
- const url = new URL(id);
119
- if (!url.hostname) {
118
+ const hostname = new URL(id).hostname;
119
+ if (!hostname) {
120
120
  throw createError("Hostname is missing", 403, id);
121
121
  }
122
- if (!reqOptions?.bypassDomain && !hosts.find((host) => url.hostname === host)) {
123
- throw createError("Forbidden host", 403, url.hostname);
122
+ if (!reqOptions?.bypassDomain && !domains.find((domain) => hostname === domain)) {
123
+ throw createError("Forbidden host", 403, hostname);
124
124
  }
125
125
  const response = await fetch(id, {
126
126
  agent: id.startsWith("https") ? httpsAgent : httpAgent,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ipx",
3
- "version": "0.9.7",
3
+ "version": "0.9.8",
4
4
  "repository": "unjs/ipx",
5
5
  "license": "MIT",
6
6
  "exports": {