https://github.com/dahlia/x-forwarded-fetch
A middleware for fetch() behind a reverse proxy with X-Forwarded-* headers
https://github.com/dahlia/x-forwarded-fetch
Last synced: 5 months ago
JSON representation
A middleware for fetch() behind a reverse proxy with X-Forwarded-* headers
- Host: GitHub
- URL: https://github.com/dahlia/x-forwarded-fetch
- Owner: dahlia
- License: mit
- Created: 2024-05-12T12:40:26.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-18T14:45:41.000Z (over 1 year ago)
- Last Synced: 2025-05-07T21:45:51.542Z (5 months ago)
- Language: TypeScript
- Homepage: https://jsr.io/@hongminhee/x-forwarded-fetch
- Size: 9.77 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
x-forwarded-fetch
=================[![JSR][JSR badge]][JSR]
[![npm][npm badge]][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.[JSR]: https://jsr.io/@hongminhee/x-forwarded-fetch
[JSR badge]: https://jsr.io/badges/@hongminhee/x-forwarded-fetch
[npm]: https://npmjs.com/package/x-forwarded-fetch
[npm badge]: https://img.shields.io/npm/v/x-forwarded-fetch?logo=npmInstallation
------------### Deno
~~~~ sh
deno add @hongminhee/x-forwarded-fetch
~~~~### Bun
~~~~ sh
bun add x-forwarded-fetch
~~~~### Node
~~~~ sh
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:~~~~ typescript
import { behindProxy } from "@hongminhee/x-forwarded-fetch";Deno.serve(behindProxy(req => new Response(`The URL: ${req.url}`)));
~~~~In Bun:
~~~~ typescript
import { behindProxy } from "x-forwarded-fetch";Bun.serve({
fetch: behindProxy(req => new Response(`The URL: ${req.url}`))
});
~~~~In Node with [@hono/node-server]:
~~~~ typescript
import { serve } from "@hono/node-server";
import { behindProxy } from "x-forwarded-fetch";serve({
fetch: behindProxy(req => new Response(`The URL: ${req.url}`))
});
~~~~[@hono/node-server]: https://github.com/honojs/node-server