1.0.0 • Published 4 months ago

fhy-reverse-proxy v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

Reverse Proxy

This project demonstrates how to set up a reverse proxy in a Node.js application using the fhy-reverse-proxy library. The reverse proxy allows you to redirect requests from one endpoint to another, while optionally modifying the path and headers.

Installation

To get started, clone this repository and install the necessary dependencies.

npm i fhy-reverse-proxy

Usage

After setting up your project, you can create a simple reverse proxy using the fhy-reverse-proxy library. Below is an example of how to configure the reverse proxy:

const CRP = require('fhy-reverse-proxy');

app.use('/your-endpoint', 
  CRP('https://target-domain.com', { 
    pathRewrite: { '^/new/path': '/origin/path' },
    changeOrigin: true,
    cache: true,
  })
);

Explanation of the Options:

OptionDescription
pathRewriteThis option allows you to rewrite the path of the request. In this example, requests that start with /new/path will be forwarded as /origin/path to the target domain.
changeOriginThis option is used to modify the Origin header of the request to match the target domain. This is useful when the target server expects requests to come from a specific origin.
cacheWhen enabled, the response is cached, which can improve performance for repeated requests.