# warp-proxy

> Proxy requests or return mocks from local files instead

Latest version **1.7.0** (published 2021-07-16) · MIT license · 0 weekly downloads

## Install

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

Provides the command `warp-proxy`.

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.7.0 |
| Published | 2021-07-16 |
| First published | 2020-02-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 105.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Renan Borges |
| Maintainers | thealgorithm, renanborgez |
| Keywords | cli, proxy, mock, api, http, https, test, cors |

## Links

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

## Dependencies (4)

- [pump](https://npm.io/package/pump.md) ^3.0.0
- [chalk](https://npm.io/package/chalk.md) ^3.0.0
- [yargs](https://npm.io/package/yargs.md) ^15.1.0
- [http-proxy](https://npm.io/package/http-proxy.md) ^1.18.0

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 1.7.0 (latest) — 2021-07-16
- 1.6.2 — 2020-06-10
- 1.6.1 — 2020-06-09
- 1.6.0 — 2020-04-23
- 1.5.0 — 2020-04-23
- 1.4.1 — 2020-04-23
- 1.4.0 — 2020-04-21
- 1.3.5 — 2020-02-27
- 1.3.4 — 2020-02-27
- 1.3.3 — 2020-02-27
- 1.3.2 — 2020-02-24
- 1.3.1 — 2020-02-21
- 1.3.0 — 2020-02-21
- 1.2.0 — 2020-02-21
- 1.1.0 — 2020-02-20
- … 1 more at https://npm.io/package/warp-proxy/versions

## README

<h1 align="center">
  <a href="https://www.wearereasonablepeople.com/">
    warp-proxy
  </a>
</h1>

<p align="center">
  <strong>Proxy it. No wait,  mock it!</strong><br />
  <strong>Just delicious when testing and developing.</strong><br />
  <span>Relies on <a href="https://github.com/http-party/node-http-proxy">
    node-http-proxy</a> and <a href="https://nodejs.org/api/http.html">
    node http api
  </a></span>
</p>

<p align="center">
  <img src="docs/cli.png" alt="Cli" />
</p>

## Description
A simple command line to quickly start a web server which proxys your requests to an external server, or to local files (JSON).
Very helpful for testing and development.

*Not made to be used in production. Use at your own risk.*

## Getting Started

Install warp-proxy using [`npm`](https://www.npmjs.com/):

```bash
npm install warp-proxy # globally accessible

npm install warp-proxy --save-dev # only accessible via npm package.json commands
```

## Usage
```bash
# Proxying all requests to a remote server
warp-proxy web --port 6543 --target http://mydesiredserver:1234 

# Proxying all request to local json files
warp-proxy mock --port 6543 --directory ./mymocksfolder/

# Using a config.js file
warp-proxy run --config ./proxy-config.js

# Using npx you don't even need to install the package
npx warp-proxy web --port 6543 --target http://mydesiredserver:1234
```

### Web

The web mode listens to a port on your local machine and sends all requests to a specified remote server.

| Argument | Required? | Description | Default |
|----------|-----------|-------------|---------|
| --port / -p | true | Port to be used by the local server | - |
| --target / -t | true | Address of the server to send your requests | - |

### Mock

The mock mode to a port on your local machine and serves a mock directory of JSON files.

| Argument | Required? | Description | Default |
|----------|-----------|-------------|---------|
| --port / -p | true | Port to be used by the local server | - |
| --directory / -d | true | Directory to read the mock files | - |
| --fileExtension / -fe | false | File exntesion of the mock files | `json` |
| --keepExtensions / -ke | false | If the request ends with a file extension, use it instead | `true` |
| --slowMode / -sm | Applies a random delay between 0 and 7s to the response | `false` |

### Run Configuration

The run mode allows for running `warp-proxy` with a configuration script written in JS.

| Argument | Required? | Description | Default |
|----------|-----------|-------------|---------|
| --config / -c | true | Path to the JavaScript configuration file | - |

👇 The format and options of the configuration script are described below in the [Configuration](#Configuration) section.

## Configuration
When using the `run` command you can pass a custom configuration via the `--config` argument.

```js
module.exports = {
  mode: 'web', // or 'mock'
  port: 1234,
  silent: false,

  // Proxying external servers
  target: 'http://mydesiredserver:1234',

  // Proxying local files
  directory: './folder/with/mocks',
}
```

## Proxying a web target
Relies on all properties from [node-http-proxy](https://github.com/http-party/node-http-proxy#options)

Feel free to extend your config file with any property from `node-http-proxy`

```js
module.exports = {
  port: 1234,
  target: 'http://mydesiredserver:1234',
  ...node_http_proxy_properties
}
```

## Proxying local files
Assuming your directory is: `--directory ./root/`

To mock the following request: 
```c#
[GET] http://address:1234/repositories/administrators/1234?param=value
└───────────────────────┘ └──────────┘ └────────────┘ └──────────────┘
   root folder + /GET/   |   FOLDER   |    FOLDER    |    JSON FILE
```

your folder structure should look like this
```bash
└─root
  └─GET
    └─repositories
      └─administrators
        └─1234?param=value.json
```




Here's a second example:
```c#
[PUT] http://address:1234/language/countries/`
└───────────────────────┘ └──────┘ └───────┘
   root folder + /PUT/   | FOLDER |JSON FILE
```

your folder structure should look like this

```bash
└─root
  └─PUT
    └─language
      └─countries.json
```

## License

[MIT licensed](./LICENSE)

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