Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,43 @@ async function run () {
}
t.ok(errored)
})

test('multiple prefixes with multiple plugins', async (t) => {
const origin2 = Fastify()

origin2.get('/', async (request, reply) => {
return 'this is root for origin2'
})

await origin2.listen(0)

const proxyServer = Fastify()

// register first proxy on /api
proxyServer.register(proxy, {
upstream: `http://localhost:${origin.server.address().port}`,
prefix: '/api'
})

// register second proxy on /api2
proxyServer.register(proxy, {
upstream: `http://localhost:${origin2.server.address().port}`,
prefix: '/api2'
})

await proxyServer.listen(0)

t.tearDown(() => {
origin2.close()
proxyServer.close()
})

const firstProxyPrefix = await got(`http://localhost:${proxyServer.server.address().port}/api`)
t.equal(firstProxyPrefix.body, 'this is root')

const secondProxyPrefix = await got(`http://localhost:${proxyServer.server.address().port}/api2`)
t.equal(secondProxyPrefix.body, 'this is root for origin2')
})
}

run()