1.0.1 • Published 2 years ago

koa-forwardproxy v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

koa forwardproxy

With this koa middleware, you can forward requests to a different server and return the response to the user, effectively making your webserver into a webproxy. The package currently only exports CommonJS, but it can also just be imported into ESM. It is written in typescript and fully typed. Typedef (.d.ts) files are included in npm releases.

Installation

npm i koa-forwardproxy

Usage

import proxy from "koa-forwardproxy";
import Koa from "koa";
const app = new Koa();

app.use(proxy({
    host: "example.com", // The host of every incoming request will be replaced with this host to send the proxied request.
    usesCloudflare: true, // If incoming requests are routed through cloudflare, you may need to enable this to clean up extra headers from cloudflare and fix HTTPS upgrading
    patchRedirects: true, // Enable to modify the URL of the `location` header on responses, which might otherwise redirect your visitor to the real, non-proxied site.  
}))
// Alternatively to using the `host` option:
app.use(proxy({
    remapUrl: (url: string)=>{
        // This gets called on each incoming request. The return value will be used as the url that the server sends.
        // This code just changes the TLD and Protocol but you can also modify the URL path etc
        let u = new URL(url);
        u.protocol = "https:";
        u.host = u.host.replace(/\.com$/, ".de")
        return u.toString();
    }
}))
1.0.1

2 years ago

1.0.0

2 years ago

0.7.2

2 years ago

0.7.1

2 years ago

0.7.0

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago