1.0.1 • Published 1 year ago

http-node-proxy-plugin v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

http-node-proxy-plugin

An http service proxy library

Install

npm i http-node-proxy-plugin

or

yarn add http-node-proxy-plugin

or

pnpm i http-node-proxy-plugin

Usage

import proxyPlugin from "http-node-proxy-plugin"
import http form "http"

const proxy = proxyPlugin({
  target: `https://localhost/`,
  changeOrigin: true,
  rewrite(path: any) {
    return path.replace(/^\/proxyApi/, '')
  },
})

const server = http.createServer((req, res) => {
  if (req.url.indexOf('/proxyApi') === 0) {
    proxy(req.url, 'GET', undefined, { headers: req.headers }).then((data) => {
      res.writeHead(200);
      res.end(data);
    })
  }
  // ...
})

server.listen(8080)