@podium/proxy
Advanced tools
Comparing version 3.0.0-beta.5 to 3.0.0
@@ -147,3 +147,6 @@ 'use strict'; | ||
process(incoming) { | ||
if (Object.prototype.toString.call(incoming) !== '[object PodiumHttpIncoming]') { | ||
if ( | ||
Object.prototype.toString.call(incoming) !== | ||
'[object PodiumHttpIncoming]' | ||
) { | ||
throw TypeError('Argument must be of type "PodiumHttpIncoming"'); | ||
@@ -229,5 +232,10 @@ } | ||
this.proxy.web(incoming.request, incoming.response, config, error => { | ||
reject(error); | ||
}); | ||
this.proxy.web( | ||
incoming.request, | ||
incoming.response, | ||
config, | ||
error => { | ||
reject(error); | ||
}, | ||
); | ||
@@ -234,0 +242,0 @@ return; |
{ | ||
"name": "@podium/proxy", | ||
"version": "3.0.0-beta.5", | ||
"version": "3.0.0", | ||
"description": "Transparent http proxy. Dynamically mounts proxy targets on an existing HTTP server instance.", | ||
@@ -36,3 +36,3 @@ "license": "MIT", | ||
"@podium/utils": "3.1.1", | ||
"abslog": "2.2.3", | ||
"abslog": "2.4.0", | ||
"http-proxy": "1.17.0", | ||
@@ -44,3 +44,3 @@ "joi": "14.3.1", | ||
"devDependencies": { | ||
"eslint": "^5.6.1", | ||
"eslint": "^5.14.1", | ||
"eslint-config-airbnb-base": "^13.1.0", | ||
@@ -47,0 +47,0 @@ "eslint-config-prettier": "^4.0.0", |
151
README.md
# @podium/proxy | ||
Transparent http proxy. Dynamically mounts proxy targets on an existing HTTP server instance. | ||
Transparent HTTP proxy. Dynamically mounts proxy targets on an existing HTTP | ||
server instance. | ||
@@ -9,2 +10,7 @@ [![Build Status](https://travis-ci.org/podium-lib/proxy.svg?branch=master)](https://travis-ci.org/podium-lib/proxy) | ||
This module is intended for internal use in Podium and is not a module an end | ||
user would use directly. End users will typically interact with this module | ||
through higher level modules such as the [@podium/layout] and [@podium/podlet] | ||
modules. | ||
## Installation | ||
@@ -18,11 +24,9 @@ | ||
Attach a proxy target to an existing Express server. | ||
Attach a proxy target to an HTTP server. | ||
```js | ||
const express = require('express'); | ||
const { HttpIncoming } = require('@podium/utils'); | ||
const Proxy = require('@podium/proxy'); | ||
const http = require('http'); | ||
// Set up express server | ||
const app = express(); | ||
// Set up proxy | ||
@@ -41,5 +45,14 @@ const proxy = new Proxy(); | ||
// Attach proxy middleware | ||
app.use(proxy.middleware()); | ||
// Attach proxy to http server | ||
const app = http.createServer(async (req, res) => { | ||
const incoming = new HttpIncoming(req, res); | ||
const result = await proxy.process(incoming); | ||
// The proxy did return "undefined" so nothing matched our proxy | ||
if (!result) { | ||
res.statusCode = 404; | ||
res.end('404 - Not found'); | ||
} | ||
}); | ||
// Start appserver where proxy is attached | ||
@@ -103,4 +116,42 @@ app.listen(9999); | ||
A Podium manifest where the `proxy` property is given. The `proxy` property is an object where the `key` identifies the target and the `property` is a URI to the target. | ||
A Podium manifest where the `proxy` property is given. The `proxy` property is | ||
an object where the `key` identifies the target and the `property` is a URI to | ||
the target. | ||
### .process(HttpIncoming) | ||
Metod for processing a incoming HTTP request. Matches the request against the | ||
registered routing targets and proxies the request if a match is found. | ||
Returns a promise. If the inbound request matches a proxy endpoint the returned | ||
Promise will resolve with `undefined`. If the inbound request does not match a | ||
proxy endpoint the returned promise will resolve with the passed in | ||
[HttpIncoming] object. | ||
The method takes the following arguments: | ||
#### HttpIncoming (required) | ||
An instance of an [HttpIncoming] class. | ||
```js | ||
const { HttpIncoming } = require('@podium/utils'); | ||
const Proxy = require('@podium/proxy'); | ||
const http = require('http'); | ||
const proxy = new Proxy(); | ||
proxy.register({ ...[snip]... }); | ||
const app = http.createServer(async (req, res) => { | ||
const incoming = new HttpIncoming(req, res); | ||
const result = await proxy.process(incoming); | ||
if (!result) { | ||
res.statusCode = 404; | ||
res.end('404 - Not found'); | ||
} | ||
}); | ||
``` | ||
### .metrics | ||
@@ -110,11 +161,8 @@ | ||
Exposes a single metric called `podium_proxy_request` which includes `podlet` and `proxy` meta fields. | ||
Exposes a single metric called `podium_proxy_request` which includes `podlet` | ||
and `proxy` meta fields. | ||
Please see the [@metrics/client](https://www.npmjs.com/package/@metrics/client) module for full documentation. | ||
Please see the [@metrics/client](https://www.npmjs.com/package/@metrics/client) | ||
module for full documentation. | ||
### .middleware() | ||
Middleware that mounts the proxy on a Connect middleware compatible | ||
HTTP server. | ||
### .dump() | ||
@@ -126,5 +174,8 @@ | ||
Loads an Array of manifests (provided by `.dump()`) into the proxy. If any of the items in the loaded Array contains a key which is already in the cache, the entry in the cache will be overwritten. | ||
Loads an Array of manifests (provided by `.dump()`) into the proxy. If any of | ||
the items in the loaded Array contains a key which is already in the cache, the | ||
entry in the cache will be overwritten. | ||
If any of the entries in the loaded Array are not compatible with the format which `.dump()` exports, they will not be inserted into the cache. | ||
If any of the entries in the loaded Array are not compatible with the format | ||
which `.dump()` exports, they will not be inserted into the cache. | ||
@@ -135,3 +186,5 @@ Returns an Array with the keys which were inserted into the cache. | ||
To be able to have multible proxy targets in an HTTP server we need to make sure that they do not collide with each other. To prevent so, each proxy target defined is mounted on their own separate namespace in an HTTP server. | ||
To be able to have multiple proxy targets in an HTTP server we need to make sure | ||
that they do not collide with each other. To prevent this, each proxy target | ||
defined is mounted on its own separate namespace in an HTTP server. | ||
@@ -152,4 +205,6 @@ The convention for these namespaces is as follow: | ||
```js | ||
const app = require('express')(); | ||
const { HttpIncoming } = require('@podium/utils'); | ||
const Proxy = require('@podium/proxy'); | ||
const http = require('http'); | ||
const proxy = new Proxy(); | ||
@@ -166,3 +221,5 @@ | ||
app.use(proxy.middleware()); | ||
const app = http.createServer(async (req, res) => { | ||
...[snip]... | ||
}); | ||
@@ -181,4 +238,6 @@ app.listen(8000); | ||
```js | ||
const app = require('express')(); | ||
const { HttpIncoming } = require('@podium/utils'); | ||
const Proxy = require('@podium/proxy'); | ||
const http = require('http'); | ||
const proxy = new Proxy({ | ||
@@ -197,3 +256,5 @@ prefix: '/my-proxy', | ||
app.use(proxy.middleware()); | ||
const app = http.createServer(async (req, res) => { | ||
...[snip]... | ||
}); | ||
@@ -212,4 +273,6 @@ app.listen(8000); | ||
```js | ||
const app = require('express')(); | ||
const { HttpIncoming } = require('@podium/utils'); | ||
const Proxy = require('@podium/proxy'); | ||
const http = require('http'); | ||
const proxy = new Proxy(); | ||
@@ -227,3 +290,5 @@ | ||
app.use(proxy.middleware()); | ||
const app = http.createServer(async (req, res) => { | ||
...[snip]... | ||
}); | ||
@@ -243,4 +308,6 @@ app.listen(8000); | ||
```js | ||
const app = require('express')(); | ||
const { HttpIncoming } = require('@podium/utils'); | ||
const Proxy = require('@podium/proxy'); | ||
const http = require('http'); | ||
const proxy = new Proxy(); | ||
@@ -267,3 +334,5 @@ | ||
app.use(proxy.middleware()); | ||
const app = http.createServer(async (req, res) => { | ||
...[snip]... | ||
}); | ||
@@ -278,1 +347,29 @@ app.listen(8000); | ||
- http://localhost:8000/podium-resource/foo/users/ | ||
## License | ||
Copyright (c) 2019 FINN.no | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
[@podium/layout]: https://github.com/podium-lib/layout "@podium/layout" | ||
[@podium/podlet]: https://github.com/podium-lib/podlet "@podium/podlet" | ||
[HttpIncoming]: https://github.com/podium-lib/utils/blob/master/lib/http-incoming.js "HttpIncoming" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
20741
219
0
360
+ Addedabslog@2.4.0(transitive)
- Removedabslog@2.2.3(transitive)
Updatedabslog@2.4.0