backend-proxy

0.0.13 • Public • Published

backend-proxy

CircleCI npm version npm

Backend proxy is a tool to route your REST API through a proxy

Install

$ npm i -g backend-proxy

Usage

$ backend-proxy --url PROXY_URL --token-name --token TOKEN --use-headers --port 3000 --read-only

Options

Option Input Default Required
--port Port on which proxy will serve requests 3000
--url Url to proxy to N/A *
--secure Listen over https instead of http. Will use a test self signed certificate false
--token-name Name of the token query parameter / header name used to pass token token
--token Token to use for requests N/A
--use-headers Pass token as a http header instead of a url query string false
--read-only Only allow GET requests false
--rewrite Transforms paths from when proxying request *
--debug Print extra information for debugging false
--secure Print extra information for debugging false

Usecases

  • Proxies cookies properly by removing the scoped domain
  • Adds proper CORs headers allowing full access from the browser
  • Supports POST requests and proxies them transparently
  • Read Only mode allows easy testing for backend APIs where accidental changes are prevented

Example

$ backend-proxy --url https://reqres.in/api

Then

GET http://localhost:3000/users/2

proxies to

GET https://reqres.in/api/users/2

Path Rewrites

--rewrite option can be used multiple times to transform many paths like so:

$ backend-proxy --url https://reqres.in/api --rewrite "/users -> /clients" --rewrite "/customers -> /clients"

Then

GET http://localhost:3000/users/2
GET http://localhost:3000/customers/4

proxies to

GET https://reqres.in/api/clients/2
GET https://reqres.in/api/clients/4

URL mappings

--map option can be used to select a url if multiple urls are given. This can be used in scenarios where multiple paths map to different urls.

$ backend-proxy --url http://url_1.com --url http://url_2.com --map "/users -> 0" --map "/posts -> 1"

In above example, /users/25 will proxy to http://url_1.com/users/25 where as /posts/22 will proxy to http://url_2.com/posts/22 Note that url that comes first gets precedence. Either the first mapping matched will be used, or fall back to first url given. The mapped number is an index, and starts from 0 not 1

License

Licensed under the MIT License

View this on npm

Made with ❤ by Rikin Katyal

Readme

Keywords

none

Package Sidebar

Install

npm i backend-proxy

Weekly Downloads

2

Version

0.0.13

License

MIT

Unpacked Size

24.6 kB

Total Files

12

Last publish

Collaborators

  • hzia
  • sirvar