# ninja-proxy

> simple and easy proxy.

Latest version **1.0.1** (published 2020-08-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install ninja-proxy
pnpm add ninja-proxy
yarn add ninja-proxy
bun add ninja-proxy
```

Provides the command `ninja-proxy`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-08-22 |
| First published | 2019-08-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8.10.0 |
| Dependencies | 4 |
| Unpacked size | 25.6 KB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 20 |
| Author | Joe Wilson |
| Maintainers | joe.wilson |

## Links

- npm: https://www.npmjs.com/package/ninja-proxy
- Repository: https://github.com/jwilson64/ninja-proxy
- Homepage: https://github.com/jwilson64/ninja-proxy#readme
- Issues: https://github.com/jwilson64/ninja-proxy/issues
- npm.io page: https://npm.io/package/ninja-proxy

## Dependencies (4)

- [ws](https://npm.io/package/ws.md) ^3.3.2
- [arg](https://npm.io/package/arg.md) ^1.0.0
- [micro](https://npm.io/package/micro.md) ^9.0.2
- [node-fetch](https://npm.io/package/node-fetch.md) ^1.7.3

## Recent versions

- 1.0.1 (latest) — 2020-08-22
- 0.0.3 — 2019-09-02
- 0.0.2 — 2019-08-11
- 0.0.1 — 2019-08-10

## README

# Ninja Proxy

### What is it?

This is based off of [Zeit's micro-proxy](https://github.com/zeit/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

| Option      | Required   | Description                                                                      | Example                               |
| ----------- | ---------- | -------------------------------------------------------------------------------- | ------------------------------------- |
| pathname    | yes        | The path to listen for                                                           | `/home`                               |
| destination | yes and no | Required if not a stub. The server your traffic is going to                      | `http://localhost:3000`               |
| rewrite     | no         | Rewrite your path to specific path on the server. Example: `/home` to `/`        | `/`                                   |
| headers     | no         | a JSON element of extra headers to pass along                                    | `{ x-forwarded-host: 'mydomain.com'}` |
| methods     | no         | array of HTTP methods that may be used on this endpoint. If blank all are valid  | `['GET', 'POST', 'PUT']`              |
| stub        | yes and no | Required if it is a stub. This is JSON data to return if you want to mock an API | `{"data": "test"}`                    |

---
_Source: https://npm.io/package/ninja-proxy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
