Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fastify-http-proxy

Package Overview
Dependencies
Maintainers
13
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-http-proxy - npm Package Compare versions

Comparing version 6.1.0 to 6.2.0

4

index.js

@@ -120,3 +120,3 @@ 'use strict'

let rewritePrefix = opts.rewritePrefix || new URL(opts.upstream).pathname
let rewritePrefix = opts.rewritePrefix || (opts.upstream ? new URL(opts.upstream).pathname : '/')

@@ -131,3 +131,3 @@ if (!prefix.endsWith('/') && rewritePrefix.endsWith('/')) {

async function httpProxy (fastify, opts) {
if (!opts.upstream) {
if (!opts.upstream && !(opts.upstream === '' && opts.replyOptions && typeof opts.replyOptions.getUpstream === 'function')) {
throw new Error('upstream must be specified')

@@ -134,0 +134,0 @@ }

{
"name": "fastify-http-proxy",
"version": "6.1.0",
"version": "6.2.0",
"description": "proxy http requests, for Fastify",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -65,2 +65,27 @@ 'use strict'

test('dynamic upstream for basic proxy', async t => {
const server = Fastify()
server.register(proxy, {
upstream: '',
replyOptions: {
getUpstream: function (original, base) {
return `http://localhost:${origin.server.address().port}`
}
}
})
await server.listen(0)
t.teardown(server.close.bind(server))
const resultRoot = await got(
`http://localhost:${server.server.address().port}`
)
t.equal(resultRoot.body, 'this is root')
const resultA = await got(
`http://localhost:${server.server.address().port}/a`
)
t.equal(resultA.body, 'this is a')
})
test('redirects passthrough', async t => {

@@ -87,2 +112,28 @@ const server = Fastify()

test('dynamic upstream for redirects passthrough', async t => {
const server = Fastify()
server.register(proxy, {
upstream: '',
replyOptions: {
getUpstream: function (original, base) {
return `http://localhost:${origin.server.address().port}`
}
}
})
await server.listen(0)
t.teardown(server.close.bind(server))
const {
headers: { location },
statusCode
} = await got(
`http://localhost:${server.server.address().port}/redirect`, {
followRedirect: false
}
)
t.equal(location, 'https://fastify.io')
t.equal(statusCode, 302)
})
test('no upstream will throw', async t => {

@@ -126,2 +177,33 @@ const server = Fastify()

test('dynamic upstream for prefixed proxy', async t => {
const server = Fastify()
server.register(proxy, {
upstream: '',
prefix: '/my-prefix',
replyOptions: {
getUpstream: function (original, base) {
return `http://localhost:${origin.server.address().port}`
}
}
})
await server.listen(0)
t.teardown(server.close.bind(server))
const resultRoot = await got(
`http://localhost:${server.server.address().port}/my-prefix/`
)
t.equal(resultRoot.body, 'this is root')
const withoutSlash = await got(
`http://localhost:${server.server.address().port}/my-prefix`
)
t.equal(withoutSlash.body, 'this is root')
const resultA = await got(
`http://localhost:${server.server.address().port}/my-prefix/a`
)
t.equal(resultA.body, 'this is a')
})
test('posting stuff', async t => {

@@ -147,2 +229,27 @@ const server = Fastify()

test('dynamic upstream for posting stuff', async t => {
const server = Fastify()
server.register(proxy, {
upstream: '',
replyOptions: {
getUpstream: function (original, base) {
return `http://localhost:${origin.server.address().port}`
}
}
})
await server.listen(0)
t.teardown(server.close.bind(server))
const resultRoot = await got(
`http://localhost:${server.server.address().port}/this-has-data`,
{
method: 'POST',
json: { hello: 'world' },
responseType: 'json'
}
)
t.same(resultRoot.body, { something: 'posted' })
})
test('skip proxying the incoming payload', async t => {

@@ -149,0 +256,0 @@ const server = Fastify()

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc