@springernature/backend-proxy
Advanced tools
Comparing version 2.1.0 to 2.2.0
# History | ||
## 2.2.0 | ||
_08/07/20_ | ||
- `backendHeaders` option added, in order to offer the ability to supplement | ||
the outgoing HTTP response headers with some of the Backend response headers. ([morgaan](https://github.com/morgaan)) | ||
## 2.1.0 | ||
@@ -4,0 +11,0 @@ _19/06/20_ |
{ | ||
"name": "@springernature/backend-proxy", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Proxies frontend requests to a backend and can render the result", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -36,3 +36,4 @@ # backend-proxy | ||
usePath: false, | ||
interceptErrors: true | ||
interceptErrors: true, | ||
backendHeaders: ['set-cookie'] | ||
}), (req, res) => { | ||
@@ -49,5 +50,6 @@ res.render('login', req.backendResponse); | ||
| `requiredContentType` | Backend response content type thats required to allow interception and deserialization | string | `application/json` | | ||
| `usePath` | Should the incoming HTTP request's path be apended to the `backend` URL | boolean | `true` | | ||
| `usePath` | Should the incoming HTTP request's path be appended to the `backend` URL | boolean | `true` | | ||
| `interceptErrors` | Should backend responses with HTTP 400 - 599 be intercepted and raised as express errors. If provided as a function, it takes the backendResponse as parameter and returns a boolean. This gives the frontend the flexibility to decided on a per-response status code basis. | undefined, boolean or function | `undefined` | | ||
| `key` | The property on the request object that the backend response will be stored under. | string | `backendResponse` | | ||
| `backendHeaders` | List of headers to copy from a Backend response to the outgoing client response (e.g. `Set-Cookie`...) | string[] | | | ||
@@ -54,0 +56,0 @@ ### `renderBackendResponse(options)` |
@@ -22,3 +22,3 @@ const http = require('http'); | ||
try { | ||
// Supplement req with data from BE | ||
// Supplement request with data from Backend | ||
request[options.key] = JSON.parse(Buffer.concat(stringBody).toString('utf8')); | ||
@@ -73,2 +73,8 @@ handled = true; | ||
if (contentType === options.requiredContentType || contentType === `${options.requiredContentType}; charset=utf-8`) { | ||
// Supplement response with headers from Backend, if needed | ||
if (Array.isArray(options.backendHeaders) && backendResponse.headers) { | ||
options.backendHeaders | ||
.filter(header => backendResponse.headers[header]) | ||
.forEach(header => response.set(header, backendResponse.headers[header])); | ||
} | ||
tryReadData(options, backendResponse, request, next); | ||
@@ -75,0 +81,0 @@ } else { |
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
20564
230
148