Skip to main content
Home

Built and signed on GitHub Actions

A middleware for fetch() behind a reverse proxy with X-Forwarded-* headers

This package works with Node.js, Deno, BunIt is unknown whether this package works with Cloudflare Workers, Browsers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
It is unknown whether this package works with Browsers
JSR Score
100%
Published
a year ago (0.2.0)

x-forwarded-fetch

JSR npm

This small library provides a middleware for fetch() behind a reverse proxy that supports X-Forwarded-Host and X-Forwarded-Proto headers.

This is useful when you have a reverse proxy in front of your server that handles SSL termination and forwards requests to your server over HTTP.

Installation

Deno

deno add @hongminhee/x-forwarded-fetch

Bun

bun add x-forwarded-fetch

Node

npm install x-forwarded-fetch

Usage

Wrap your fetch() with behindProxy() to make it aware of the X-Forwarded-Host and X-Forwarded-Proto headers. For instance, in Deno:

import { behindProxy } from "@hongminhee/x-forwarded-fetch";

Deno.serve(behindProxy(req => new Response(`The URL: ${req.url}`)));

In Bun:

import { behindProxy } from "x-forwarded-fetch";

Bun.serve({
  fetch: behindProxy(req => new Response(`The URL: ${req.url}`))
});

In Node with @hono/node-server:

import { serve } from "@hono/node-server";
import { behindProxy } from "x-forwarded-fetch";

serve({
  fetch: behindProxy(req => new Response(`The URL: ${req.url}`))
});
Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@hongminhee/x-forwarded-fetch

Import symbol

import * as x_forwarded_fetch from "@hongminhee/x-forwarded-fetch";
or

Import directly with a jsr specifier

import * as x_forwarded_fetch from "jsr:@hongminhee/x-forwarded-fetch";

Add Package

pnpm i jsr:@hongminhee/x-forwarded-fetch
or (using pnpm 10.8 or older)
pnpm dlx jsr add @hongminhee/x-forwarded-fetch

Import symbol

import * as x_forwarded_fetch from "@hongminhee/x-forwarded-fetch";

Add Package

yarn add jsr:@hongminhee/x-forwarded-fetch
or (using Yarn 4.8 or older)
yarn dlx jsr add @hongminhee/x-forwarded-fetch

Import symbol

import * as x_forwarded_fetch from "@hongminhee/x-forwarded-fetch";

Add Package

npx jsr add @hongminhee/x-forwarded-fetch

Import symbol

import * as x_forwarded_fetch from "@hongminhee/x-forwarded-fetch";

Add Package

bunx jsr add @hongminhee/x-forwarded-fetch

Import symbol

import * as x_forwarded_fetch from "@hongminhee/x-forwarded-fetch";