1.0.1 • Published 4 years ago

ninja-proxy v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

Ninja Proxy

What is it?

This is based off of Zeit's micro-proxy

The goal is to give a user a quick way to spin up a proxy.

Usage

Firstly, install the package:

npm i -g ninja-proxy

Then add following rules to a filename called rules.json:

{
  rules: [
    { "pathname": "/home", "destination": "http://localhost:3000", "rewrite": "/" },
    { "pathname": "/", "destination": "http://localhost:3000" }
  ]
}

Visit path alias documentation to learn more about rules.

Run the proxy server with:

ninja-proxy -r rules.json -p 9000 Now you can access the proxy via: http://localhost:9000

Programmatic Usage

You can run the proxy programmatically inside your codebase. For that, add ninja-proxy to your project with:

npm install ninja-proxy

Then create the proxy server like this:

const { createProxy } = require('ninja-proxy')
const proxy = createProxy([
  { "pathname": "/", "destination": "http://localhost:3000" }
])

proxy.listen(9000, (err) => {
  if (err) {
    throw err
  }
  console.log(`> Ready on http://localhost:9000`)
})

Available Options

OptionRequiredDescriptionExample
pathnameyesThe path to listen for/home
destinationyes and noRequired if not a stub. The server your traffic is going tohttp://localhost:3000
rewritenoRewrite your path to specific path on the server. Example: /home to //
headersnoa JSON element of extra headers to pass along{ x-forwarded-host: 'mydomain.com'}
methodsnoarray of HTTP methods that may be used on this endpoint. If blank all are valid['GET', 'POST', 'PUT']
stubyes and noRequired if it is a stub. This is JSON data to return if you want to mock an API{"data": "test"}
1.0.1

4 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago

1.0.0

5 years ago