1.0.11 • Published 4 years ago

hc-mid-proxy v1.0.11

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
4 years ago

hc-mid-proxy

honeycomb middleware for proxy request.

Install

npm i -S hc-mid-proxy

Usage

NOTICE: this middleware should be placed BEFORE body-parser

SEE: https://github.com/chimurai/http-proxy-middleware/issues/40

In your config_default.js, add below line:

config = {
    middleware: {
        bodyParser: {
            deps: 'proxy'
        },
        proxy: {
            enable: true,
            module: 'hc-mid-proxy',
            config: {                
                prefix: '/api/proxy/abc/',
                endpoint: 'http://backend.host:8888/abc/',
                headerExtension: [],
                api: ['/abc']
            }
        }
    }
}

Default value of headerExtension is [], and api is [], when omitted.

When want to proxy many routes, using routes format as below:

config = {
    middleware: {
        proxy: {
            enable: true,
            module: 'hc-mid-proxy',
            config: { 
                routes: [
                    {
                        prefix: '/api/proxy1',
                        endpoint: 'http://backend.host:8888',
                        api: [
                            '/abc'
                        ]
                    },
                    {
                        prefix: '/api/proxy2',
                        endpoint: 'http://backend.host:9999',
                        api: [
                            '/abc'
                        ]
                    },
                ]
            }
        }
    }
}

Notice both prefix and endpoint can omit the suffix /.

The api: [] can include below format:

{
    path: '/abc',
    method: 'get|post',
    onRequest: req=>{
        // Throw error when validate failed
        throw 'Validate failed'
    }
}
1.0.11

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago