x-forwarded-fetch
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

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}`))
});

Package Sidebar

Install

npm i x-forwarded-fetch

Weekly Downloads

45

Version

0.2.0

License

MIT

Unpacked Size

14 kB

Total Files

22

Last publish

Collaborators

  • hongminhee