@nicky9112/exproxy
express http proxy middleware
Last updated 3 years ago by nicky9112 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @nicky9112/exproxy 
SYNC missed versions from official npm registry.

exproxy

Build StatusCoverage Status

exproxy is designed to be the simplest way possible to make proxy http calls. It build from express router and just need some config file you will make proxy server.

Install

yarn

yarn add @nicky9112/exproxy

npm

npm i @nicky9112/exproxy --save

Usage

app.js

var express = require('express'),
    exproxy = require('@nicky9112/exproxy'),
    
    app = express(),
    router = express.Router(),
    config = {
		// eg: path.resolve('./proxy-router') + '/**.json'
		routePath: '$YOUR_ROUTER_PATH/**.js*', 
		// or
		routeFiles: [
			'/$YOUR_ROUTER_PATH/xx.js',
			'/$YOUR_ROUTER_PATH/xxx.json'
		],
		mock: true, // enable mock if true mockRouterPath parameter is require
		// eg: path.resolve('./proxy-router-mock') + '/**.json'
		mockRoutePath: '$YOUR_MOCK_ROUTER_PATH/**.js*',
		apiMap: { // required
      		data: 'http://127.0.0.1:5000',
      		other: 'http://127.0.0.1:6000'
    	}
	};

// some other middlewares eg: body-parser ...

app.use(exproxy(router, config));

app.listen(3000);

proxy router *.json or *.js

[
  {
    "url": "/users/:id",
    "target": "/users/:id",
    "api": "data",
    "method": "GET",
    "desc": "user detail"
  },
  {
    "url": "/users",
    "target": "/users",
    "api": "data",
    "method": "POST",
    "desc": "add user"
  },
  {
    "url": "/users/:id/other",
    "target": "/users/:id/other",
    "api": "data",
    "method": "GET",
    "desc": "user detail"
  }
]

mock proxy router *.js or *.json

module.exports = [
  {
    url: '/users/:id/other', // should mapping proxy route url
    method: 'GET',
    mockData: { // everything you like
      user: true
    }
  }
];

exproxy will read routePath or routeFiles and concat each item to make a express route.

now request your app server will forward data api that you declare in *.js*.

Licence

MIT

Current Tags

  • 2.4.1                                ...           latest (3 years ago)

8 Versions

  • 2.4.1                                ...           3 years ago
  • 2.4.0                                ...           3 years ago
  • 2.3.0                                ...           3 years ago
  • 2.2.0                                ...           3 years ago
  • 2.1.0                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 1
This Week 1
This Month 3
Last Day 0
Last Week 0
Last Month 1
Dependencies (4)
Dev Dependencies (9)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |