Registry / devops / x-forwarded-fetch

x-forwarded-fetch

JSON →
library0.2.0jsnpmunverified

A small middleware for fetch() that adjusts request URLs based on X-Forwarded-Host and X-Forwarded-Proto headers when running behind a reverse proxy. Version 0.2.0, stable. Key differentiator: lightweight, zero-dependency, works across Deno, Bun, and Node.js (uses @hono/node-server). Handles proxy-aware URL reconstruction without modifying existing fetch handlers.

npm install x-forwarded-fetch
INSTALL
IMPORT
SIG · X-FORWARDED-FETCH
X
x-forwarded-fetch
devopsjavascriptv0.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

behindProxy
import { behindProxy } from 'x-forwarded-fetch'
import behindProxy from 'x-forwarded-fetch'
ESM only; named export.
None (type)
import type { FetchHandler } from 'x-forwarded-fetch'
TypeScript users can import the FetchHandler type.
Deno import
import { behindProxy } from '@hongminhee/x-forwarded-fetch'
Deno uses JSR package registry; path includes scope.

Node.js example: wraps a fetch handler with behindProxy to show proxied URL.

import { behindProxy } from 'x-forwarded-fetch'; import { serve } from '@hono/node-server'; const handler = behindProxy((req) => { const url = new URL(req.url); return new Response(`Original URL: ${url.href}`); }); serve({ fetch: handler, port: 3000 });
Debug
Known issues
gotchaImport path differs between Deno (@hongminhee/x-forwarded-fetch) and npm (x-forwarded-fetch). Using the wrong path causes module not found.
fix
Use '@hongminhee/x-forwarded-fetch' in Deno, 'x-forwarded-fetch' in Bun/Node.
affects: >=0.1.0
gotchabehindProxy only handles X-Forwarded-Host and X-Forwarded-Proto. Other headers like X-Forwarded-For are ignored.
fix
If you need other X-Forwarded-* headers, combine with additional middleware.
affects: >=0.1.0
breakingVersion 0.x may have breaking changes in minor releases.
fix
Pin version to avoid unexpected changes.
affects: >=0.1.0
Errors
Common errors & fixes
Module not found: "@hongminhee/x-forwarded-fetch"
Trying to use the Deno import path in Node.js or Bun.
fix
Use 'x-forwarded-fetch' instead of '@hongminhee/x-forwarded-fetch'.
behindProxy is not a function
Using default import instead of named import.
fix
Use import { behindProxy } from 'x-forwarded-fetch'.
Request URL is not being modified
Request might not have X-Forwarded headers, or fetch handler is not wrapped correctly.
fix
Ensure the proxy sends headers and that the handler is wrapped: behindProxy(yourHandler).
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
@hono/node-serveroptionalRequired for Node.js integration to serve HTTP; not needed for Deno or Bun.
Agent activity
18 hits · last 30 days
node
16
Amazon
1
Resources
x-forwarded-fetch — npm install x-forwarded-fetch · libregistry