Skip to content

Commit b42a27e

Browse files
committed
Improved test suite with test to check ambigous/overlapping prefixs
1 parent 4034126 commit b42a27e

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,43 @@ async function run () {
121121
}
122122
t.ok(errored)
123123
})
124+
125+
test('multiple prefixes with multiple plugins', async (t) => {
126+
const origin2 = Fastify()
127+
128+
origin2.get('/', async (request, reply) => {
129+
return 'this is root for origin2'
130+
})
131+
132+
await origin2.listen(0)
133+
134+
const proxyServer = Fastify()
135+
136+
// register first proxy on /api
137+
proxyServer.register(proxy, {
138+
upstream: `http://localhost:${origin.server.address().port}`,
139+
prefix: '/api'
140+
})
141+
142+
// register second proxy on /api2
143+
proxyServer.register(proxy, {
144+
upstream: `http://localhost:${origin2.server.address().port}`,
145+
prefix: '/api2'
146+
})
147+
148+
await proxyServer.listen(0)
149+
150+
t.tearDown(() => {
151+
origin2.close()
152+
proxyServer.close()
153+
})
154+
155+
const firstProxyPrefix = await got(`http://localhost:${proxyServer.server.address().port}/api`)
156+
t.equal(firstProxyPrefix.body, 'this is root')
157+
158+
const secondProxyPrefix = await got(`http://localhost:${proxyServer.server.address().port}/api2`)
159+
t.equal(secondProxyPrefix.body, 'this is root for origin2')
160+
})
124161
}
125162

126163
run()

0 commit comments

Comments
 (0)