Skip to content

Commit

Permalink
Add test keep the query params on proxy without params in prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
amorgunov committed Jul 17, 2024
1 parent e38c3ad commit ae5cacd
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ async function run () {
return `this is "variable-api" endpoint with id ${request.params.id} and query params ${JSON.stringify(request.query)}`
})

origin.get('/api/endpoint-with-query', async (request, reply) => {
return `this is "api" endpoint with query params ${JSON.stringify(request.query)}`
})

origin.get('/timeout', async (request, reply) => {
await new Promise((resolve) => setTimeout(resolve, 600))
return 'this is never received'
Expand Down Expand Up @@ -917,6 +921,28 @@ async function run () {
const queryParams = JSON.stringify(qs.parse('foo=bar&foo=baz&abc=qux'))
t.equal(firstProxyPrefix.body, `this is "variable-api" endpoint with id 123 and query params ${queryParams}`)
})

test('keep the query params on proxy without params in prefix', { only: true }, async t => {
const proxyServer = Fastify()

proxyServer.register(proxy, {
upstream: `http://localhost:${origin.server.address().port}`,
prefix: '/api/endpoint',
rewritePrefix: '/api/endpoint-with-query'
})

await proxyServer.listen({ port: 0 })

t.teardown(() => {
proxyServer.close()
})

const firstProxyPrefix = await got(
`http://localhost:${proxyServer.server.address().port}/api/endpoint?foo=bar&foo=baz&abc=qux`
)
const queryParams = JSON.stringify(qs.parse('foo=bar&foo=baz&abc=qux'))
t.equal(firstProxyPrefix.body, `this is "api" endpoint with query params ${queryParams}`)
})
}

run()

0 comments on commit ae5cacd

Please sign in to comment.