@fastify/http-proxy
Advanced tools
Comparing version 7.0.0 to 7.1.0
10
index.js
@@ -93,5 +93,13 @@ 'use strict' | ||
let optionsWs = {} | ||
if (request.headers.cookie) { | ||
const headers = { cookie: request.headers.cookie } | ||
optionsWs = { ...options.wsClientOptions, headers } | ||
} else { | ||
optionsWs = options.wsClientOptions | ||
} | ||
const url = createWebSocketUrl(request) | ||
const target = new WebSocket(url, options.wsClientOptions) | ||
const target = new WebSocket(url, optionsWs) | ||
@@ -98,0 +106,0 @@ fastify.log.debug({ url: url.href }, 'proxy websocket') |
{ | ||
"name": "@fastify/http-proxy", | ||
"version": "7.0.0", | ||
"version": "7.1.0", | ||
"description": "proxy http requests, for Fastify", | ||
@@ -11,4 +11,3 @@ "main": "index.js", | ||
"lint:typescript": "npm run lint:fix - --parser @typescript-eslint/parser --plugin typescript \"test/types/*.ts\"", | ||
"test:disabled": "npm run lint && tap \"test/*.js\" && npm run typescript", | ||
"test": "npm run lint && tap \"test/*.js\"", | ||
"test": "npm run lint && tap \"test/*.js\" && npm run typescript", | ||
"typescript": "tsd" | ||
@@ -50,5 +49,5 @@ }, | ||
"socket.io-client": "^4.4.1", | ||
"standard": "^16.0.4", | ||
"standard": "^17.0.0", | ||
"tap": "^16.0.0", | ||
"tsd": "^0.19.1", | ||
"tsd": "^0.20.0", | ||
"typescript": "^4.5.4" | ||
@@ -55,0 +54,0 @@ }, |
@@ -1,5 +0,5 @@ | ||
# fastify-http-proxy | ||
# @fastify/http-proxy | ||
![CI](https://github.com/fastify/fastify-http-proxy/workflows/CI/badge.svg) | ||
[![NPM version](https://img.shields.io/npm/v/fastify-http-proxy.svg?style=flat)](https://www.npmjs.com/package/fastify-http-proxy) | ||
[![NPM version](https://img.shields.io/npm/v/@fastify/http-proxy.svg?style=flat)](https://www.npmjs.com/package/@fastify/http-proxy) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/fastify/fastify-http-proxy/badge.svg)](https://snyk.io/test/github/fastify/fastify-http-proxy) | ||
@@ -12,4 +12,4 @@ [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/) | ||
`fastify-http-proxy` is built on top of | ||
[`fastify-reply-from`](http://npm.im/fastify-reply-from), which enables single route proxying. | ||
`@fastify/http-proxy` is built on top of | ||
[`@fastify/reply-from`](http://npm.im/fastify-reply-from), which enables single route proxying. | ||
@@ -25,3 +25,3 @@ This plugin can be used in a variety of circumstances, for example if you have to proxy an internal domain to an external domain (useful to avoid CORS problems) or to implement your own API gateway for a microservices architecture. | ||
``` | ||
npm i fastify-http-proxy fastify | ||
npm i @fastify/http-proxy fastify | ||
``` | ||
@@ -35,3 +35,3 @@ | ||
server.register(require('fastify-http-proxy'), { | ||
server.register(require('@fastify/http-proxy'), { | ||
upstream: 'http://my-api.example.com', | ||
@@ -52,3 +52,3 @@ prefix: '/api', // optional | ||
const server = Fastify() | ||
const proxy = require('fastify-http-proxy') | ||
const proxy = require('@fastify/http-proxy') | ||
@@ -81,7 +81,7 @@ // /api/x will be proxied to http://my-api.example.com/x | ||
`fastify-http-proxy` can track and pipe the `request-id` across the upstreams. Using the [`hyperid`](https://www.npmjs.com/package/hyperid) module and the [`fastify-reply-from`](https://github.com/fastify/fastify-reply-from) built-in options a fairly simple example would look like this: | ||
`@fastify/http-proxy` can track and pipe the `request-id` across the upstreams. Using the [`hyperid`](https://www.npmjs.com/package/hyperid) module and the [`@fastify/reply-from`](https://github.com/fastify/fastify-reply-from) built-in options a fairly simple example would look like this: | ||
```js | ||
const Fastify = require('fastify') | ||
const proxy = require('fastify-http-proxy') | ||
const proxy = require('@fastify/http-proxy') | ||
const hyperid = require('hyperid') | ||
@@ -106,3 +106,3 @@ | ||
This `fastify` plugin supports _all_ the options of | ||
[`fastify-reply-from`](https://github.com/fastify/fastify-reply-from) plus the following. | ||
[`@fastify/reply-from`](https://github.com/fastify/fastify-reply-from) plus the following. | ||
@@ -153,3 +153,3 @@ *Note that this plugin is fully encapsulated, and non-JSON payloads will | ||
Object with [reply options](https://github.com/fastify/fastify-reply-from#replyfromsource-opts) for `fastify-reply-from`. | ||
Object with [reply options](https://github.com/fastify/fastify-reply-from#replyfromsource-opts) for `@fastify/reply-from`. | ||
@@ -163,6 +163,6 @@ ### httpMethods | ||
`websocket` option. All those options are going to be forwarded to | ||
[`fastify-websocket`](https://github.com/fastify/fastify-websocket). | ||
[`@fastify/websocket`](https://github.com/fastify/fastify-websocket). | ||
A few things are missing: | ||
1. forwarding headers as well as `rewriteHeaders` | ||
1. forwarding headers as well as `rewriteHeaders`. Note: Only cookie headers are being forwarded | ||
2. request id logging | ||
@@ -182,3 +182,3 @@ 3. support `ignoreTrailingSlash` | ||
| `http-proxy` | 9519 | | ||
| `fastify-http-proxy` | 15919 | | ||
| `@fastify/http-proxy` | 15919 | | ||
@@ -185,0 +185,0 @@ The results were gathered on the second run of `autocannon -c 100 -d 5 |
@@ -45,7 +45,2 @@ import fastify, { RawReplyDefaultExpression, RawRequestDefaultExpression } from 'fastify'; | ||
}, | ||
keepAliveMsecs: 60000, | ||
maxFreeSockets: 10, | ||
maxSockets: 20, | ||
rejectUnauthorized: true, | ||
sessionTimeout: 30000, | ||
constraints: { version: '1.0.2' } | ||
@@ -52,0 +47,0 @@ }); |
@@ -10,5 +10,6 @@ 'use strict' | ||
const { once } = require('events') | ||
const cookieValue = 'foo=bar' | ||
test('basic websocket proxy', async (t) => { | ||
t.plan(2) | ||
t.plan(3) | ||
@@ -20,3 +21,4 @@ const origin = createServer() | ||
wss.on('connection', (ws) => { | ||
wss.on('connection', (ws, request) => { | ||
t.equal(request.headers.cookie, cookieValue) | ||
ws.on('message', (message) => { | ||
@@ -40,3 +42,4 @@ t.equal(message.toString(), 'hello') | ||
const ws = new WebSocket(`ws://localhost:${server.server.address().port}`) | ||
const options = { headers: { cookie: cookieValue } } | ||
const ws = new WebSocket(`ws://localhost:${server.server.address().port}`, options) | ||
@@ -43,0 +46,0 @@ await once(ws, 'open') |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
51597
1335
6