fastify-http-proxy
Advanced tools
Comparing version 4.3.1 to 4.4.0
@@ -8,2 +8,3 @@ 'use strict' | ||
const origin = Fastify() | ||
origin.get('/', async (request, reply) => { | ||
@@ -13,2 +14,6 @@ return 'this is root' | ||
origin.get('/redirect', async (request, reply) => { | ||
return reply.redirect(302, 'https://fastify.io') | ||
}) | ||
origin.get('/a', async (request, reply) => { | ||
@@ -15,0 +20,0 @@ return 'this is a' |
'use strict' | ||
const From = require('fastify-reply-from') | ||
@@ -7,2 +6,3 @@ const WebSocket = require('ws') | ||
const httpMethods = ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT', 'OPTIONS'] | ||
const urlPattern = /^https?:\/\// | ||
@@ -35,2 +35,6 @@ function liftErrorCode (code) { | ||
function isExternalUrl (url = '') { | ||
return urlPattern.test(url) | ||
}; | ||
function proxyWebSockets (source, target) { | ||
@@ -153,3 +157,3 @@ function close (code, reason) { | ||
const location = headers.location | ||
if (location) { | ||
if (location && !isExternalUrl(location)) { | ||
headers.location = location.replace(rewritePrefix, fastify.prefix) | ||
@@ -156,0 +160,0 @@ } |
{ | ||
"name": "fastify-http-proxy", | ||
"version": "4.3.1", | ||
"version": "4.4.0", | ||
"description": "proxy http requests, for Fastify", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -20,2 +20,6 @@ 'use strict' | ||
origin.get('/redirect', async (request, reply) => { | ||
return reply.redirect(302, 'https://fastify.io') | ||
}) | ||
origin.post('/this-has-data', async (request, reply) => { | ||
@@ -62,2 +66,23 @@ if (request.body.hello === 'world') { | ||
test('redirects passthrough', async t => { | ||
const server = Fastify() | ||
server.register(proxy, { | ||
upstream: `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 => { | ||
@@ -64,0 +89,0 @@ const server = Fastify() |
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
37501
917