@remix-run/fetch-proxy 0.7.0 → 0.7.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
@@ -2,16 +2,18 @@
2
2
 
3
3
  `fetch-proxy` is an HTTP proxy for the [JavaScript Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
4
4
 
5
+ HTTP proxies are essential for many web architectures: load balancing, API gateways, development servers that forward to backend services, and middleware that needs to intercept and modify traffic. Traditional proxy implementations often require platform-specific APIs or complex server setups.
6
+
5
7
  In the context of servers, an HTTP proxy server is a server that forwards all requests it receives to another server and returns the responses it receives. When you think about it this way, a [`fetch` function](https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch) is like a mini proxy server sitting right there in your code. You send it requests, it goes and talks to some other server, and it gives you back the response it received.
6
8
 
7
- `fetch-proxy` allows you to easily create `fetch` functions that act as proxies to "target" servers.
9
+ `fetch-proxy` allows you to easily create `fetch` functions that act as proxies to "target" servers using the familiar web-standard Fetch API.
8
10
 
9
11
  ## Features
10
12
 
11
- - Built on the standard [JavaScript Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
12
- - Supports rewriting `Set-Cookie` headers received from target server
13
- - Supports `X-Forwarded-Proto` and `X-Forwarded-Host` headers
14
- - Supports custom `fetch` implementations
13
+ - **Web Standards** - Built on the standard [JavaScript Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
14
+ - **Cookie Rewriting** - Supports rewriting `Set-Cookie` headers received from target server
15
+ - **Forwarding Headers** - Supports `X-Forwarded-Proto` and `X-Forwarded-Host` headers
16
+ - **Custom Fetch** - Supports custom `fetch` implementations
15
17
 
16
18
  ## Installation
17
19
 
@@ -1,33 +1,48 @@
1
+ /**
2
+ * Options for `createFetchProxy`.
3
+ */
1
4
  export interface FetchProxyOptions {
2
5
  /**
3
- * The `fetch` function to use for the actual fetch. Defaults to the global `fetch` function.
6
+ * The `fetch` function to use for the actual fetch.
7
+ *
8
+ * @default globalThis.fetch
4
9
  */
5
10
  fetch?: typeof globalThis.fetch;
6
11
  /**
7
12
  * Set `false` to prevent the `Domain` attribute of `Set-Cookie` headers from being rewritten. By
8
13
  * default the domain will be rewritten to the domain of the incoming request.
14
+ *
15
+ * @default true
9
16
  */
10
17
  rewriteCookieDomain?: boolean;
11
18
  /**
12
19
  * Set `false` to prevent the `Path` attribute of `Set-Cookie` headers from being rewritten. By
13
20
  * default the portion of the pathname that matches the proxy target's pathname will be removed.
21
+ *
22
+ * @default true
14
23
  */
15
24
  rewriteCookiePath?: boolean;
16
25
  /**
17
26
  * Set `true` to add `X-Forwarded-Proto` and `X-Forwarded-Host` headers to the proxied request.
18
- * Defaults to `false`.
27
+ *
28
+ * @default false
19
29
  */
20
30
  xForwardedHeaders?: boolean;
21
31
  }
22
32
  /**
23
33
  * A [`fetch` function](https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch)
24
34
  * that forwards requests to another server.
35
+ *
36
+ * @param input The URL or request to forward
37
+ * @param init Optional request init options
38
+ * @returns A promise that resolves to the proxied response
25
39
  */
26
40
  export interface FetchProxy {
27
41
  (input: URL | RequestInfo, init?: RequestInit): Promise<Response>;
28
42
  }
29
43
  /**
30
44
  * Creates a `fetch` function that forwards requests to another server.
45
+ *
31
46
  * @param target The URL of the server to proxy requests to
32
47
  * @param options Options to customize the behavior of the proxy
33
48
  * @returns A fetch function that forwards requests to the target server
@@ -1 +1 @@
1
- {"version":3,"file":"fetch-proxy.d.ts","sourceRoot":"","sources":["../../src/lib/fetch-proxy.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;IAC/B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,CAAC,KAAK,EAAE,GAAG,GAAG,WAAW,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CAClE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,UAAU,CAoF9F"}
1
+ {"version":3,"file":"fetch-proxy.d.ts","sourceRoot":"","sources":["../../src/lib/fetch-proxy.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;IAC/B;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,UAAU;IACzB,CAAC,KAAK,EAAE,GAAG,GAAG,WAAW,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CAClE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,UAAU,CAoF9F"}
@@ -1,6 +1,7 @@
1
1
  import { SetCookie } from '@remix-run/headers';
2
2
  /**
3
3
  * Creates a `fetch` function that forwards requests to another server.
4
+ *
4
5
  * @param target The URL of the server to proxy requests to
5
6
  * @param options Options to customize the behavior of the proxy
6
7
  * @returns A fetch function that forwards requests to the target server
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix-run/fetch-proxy",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "An HTTP proxy for the web Fetch API",
5
5
  "author": "Michael Jackson <mjijackson@gmail.com>",
6
6
  "license": "MIT",
@@ -25,12 +25,12 @@
25
25
  },
26
26
  "./package.json": "./package.json"
27
27
  },
28
- "peerDependencies": {
29
- "@remix-run/headers": "^0.16.0"
28
+ "dependencies": {
29
+ "@remix-run/headers": "^0.19.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/node": "^24.6.0",
33
- "typescript": "^5.9.3"
33
+ "@typescript/native-preview": "7.0.0-dev.20251125.1"
34
34
  },
35
35
  "keywords": [
36
36
  "fetch",
@@ -38,9 +38,9 @@
38
38
  "proxy"
39
39
  ],
40
40
  "scripts": {
41
- "build": "tsc -p tsconfig.build.json",
41
+ "build": "tsgo -p tsconfig.build.json",
42
42
  "clean": "git clean -fdX",
43
- "test": "node --disable-warning=ExperimentalWarning --test './src/**/*.test.ts'",
44
- "typecheck": "tsc --noEmit"
43
+ "test": "node --disable-warning=ExperimentalWarning --test",
44
+ "typecheck": "tsgo --noEmit"
45
45
  }
46
46
  }
@@ -1,23 +1,33 @@
1
1
  import { SetCookie } from '@remix-run/headers'
2
2
 
3
+ /**
4
+ * Options for `createFetchProxy`.
5
+ */
3
6
  export interface FetchProxyOptions {
4
7
  /**
5
- * The `fetch` function to use for the actual fetch. Defaults to the global `fetch` function.
8
+ * The `fetch` function to use for the actual fetch.
9
+ *
10
+ * @default globalThis.fetch
6
11
  */
7
12
  fetch?: typeof globalThis.fetch
8
13
  /**
9
14
  * Set `false` to prevent the `Domain` attribute of `Set-Cookie` headers from being rewritten. By
10
15
  * default the domain will be rewritten to the domain of the incoming request.
16
+ *
17
+ * @default true
11
18
  */
12
19
  rewriteCookieDomain?: boolean
13
20
  /**
14
21
  * Set `false` to prevent the `Path` attribute of `Set-Cookie` headers from being rewritten. By
15
22
  * default the portion of the pathname that matches the proxy target's pathname will be removed.
23
+ *
24
+ * @default true
16
25
  */
17
26
  rewriteCookiePath?: boolean
18
27
  /**
19
28
  * Set `true` to add `X-Forwarded-Proto` and `X-Forwarded-Host` headers to the proxied request.
20
- * Defaults to `false`.
29
+ *
30
+ * @default false
21
31
  */
22
32
  xForwardedHeaders?: boolean
23
33
  }
@@ -25,6 +35,10 @@ export interface FetchProxyOptions {
25
35
  /**
26
36
  * A [`fetch` function](https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch)
27
37
  * that forwards requests to another server.
38
+ *
39
+ * @param input The URL or request to forward
40
+ * @param init Optional request init options
41
+ * @returns A promise that resolves to the proxied response
28
42
  */
29
43
  export interface FetchProxy {
30
44
  (input: URL | RequestInfo, init?: RequestInit): Promise<Response>
@@ -32,6 +46,7 @@ export interface FetchProxy {
32
46
 
33
47
  /**
34
48
  * Creates a `fetch` function that forwards requests to another server.
49
+ *
35
50
  * @param target The URL of the server to proxy requests to
36
51
  * @param options Options to customize the behavior of the proxy
37
52
  * @returns A fetch function that forwards requests to the target server