1.7.0 β€’ Published 3 years ago

warp-proxy v1.7.0

Weekly downloads
57
License
MIT
Repository
github
Last release
3 years ago

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:

npm install warp-proxy # globally accessible

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

Usage

# 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.

ArgumentRequired?DescriptionDefault
--port / -ptruePort to be used by the local server-
--target / -ttrueAddress 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.

ArgumentRequired?DescriptionDefault
--port / -ptruePort to be used by the local server-
--directory / -dtrueDirectory to read the mock files-
--fileExtension / -fefalseFile exntesion of the mock filesjson
--keepExtensions / -kefalseIf the request ends with a file extension, use it insteadtrue
--slowMode / -smApplies a random delay between 0 and 7s to the responsefalse

Run Configuration

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

ArgumentRequired?DescriptionDefault
--config / -ctruePath to the JavaScript configuration file-

πŸ‘‡ The format and options of the configuration script are described below in the Configuration section.

Configuration

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

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

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

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:

[GET] http://address:1234/repositories/administrators/1234?param=value
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
   root folder + /GET/   |   FOLDER   |    FOLDER    |    JSON FILE

your folder structure should look like this

└─root
  └─GET
    └─repositories
      └─administrators
        └─1234?param=value.json

Here's a second example:

[PUT] http://address:1234/language/countries/`
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”˜
   root folder + /PUT/   | FOLDER |JSON FILE

your folder structure should look like this

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

License

MIT licensed

1.7.0

3 years ago

1.6.2

4 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.5.0

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago