Fix typo in object assign for replyOptions#34
Conversation
|
Can you add a unit test?
Il giorno gio 10 gen 2019 alle 23:57 Alex Jones <notifications@github.com>
ha scritto:
… I believe this will fix my issue here: #33
<#33>
As far as I can tell this just breaks because the wrong variable is used
in the Object.assign let me know if this seems valid. Tests passed
locally for me.
If you need any changes let me know.
------------------------------
You can view, comment on, or merge this pull request online at:
#34
Commit Summary
- Fix typo in object assign for replyOptions
File Changes
- *M* index.js
<https://github.com/fastify/fastify-http-proxy/pull/34/files#diff-0>
(3)
Patch Links:
- https://github.com/fastify/fastify-http-proxy/pull/34.patch
- https://github.com/fastify/fastify-http-proxy/pull/34.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#34>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AADL41Yuo--bjZRgvt_Cz-2bsP9pgZKBks5vB8VagaJpZM4Z6ewv>
.
|
|
@mcollina the more I look at this the more I realize I do not actually understand one essential part. I will happily add some tests but from a usage perspective can you please assist with the following? Note I am still new to Fastify so I am also getting up to speed on some things. In This is very clear to me as the My main issue is I am not sure how to do the same with In this case I have the follwing code: As far as i can tell Thanks again for the help. |
|
You'll need to wrap that function so that fastify.register(proxy, {
upstream: 'myUrl',
prefix: '/apiProxy',
async beforeHandler(request, reply) {
console.log('beforeHandler from proxy called'); // works as expected
},
replyOptions: {
rewriteHeaders: headers => Object.assign({ 'x-from-proxy': 'yes-indeed' }, headers), // works as expected
onResponse: (req, reply, stream) => {
reply.send(stream)
},
},
}); |
|
@mcollina apologies on this. I tried that out and tried hacking in a few things here and there to |
|
Something like this should do the trick: test('passes onResponse option to reply.from()', async (t) => {
const proxyServer = Fastify()
proxyServer.register(proxy, {
upstream: `http://localhost:${origin.server.address().port}`,
prefix: '/api',
replyOptions: {
onResponse (reply) {
reply.send({ something: 'else' })
}
}
})
await proxyServer.listen(0)
t.tearDown(() => {
proxyServer.close()
})
const { body } = await got(`http://localhost:${proxyServer.server.address().port}/api`)
t.match(body, { something: 'else' })
}) |
|
fastify-reply-from was updated in fastify/fastify-reply-from#43 |
618f4f1 to
f0ae411
Compare
f0ae411 to
2cf6da3
Compare
|
@mcollina I think this is updated with all of the latest and the new test. Running it through Thanks again. |
|
|
||
| const oldRewriteHeaders = (opts.replyOptions || {}).rewriteHeaders | ||
| const replyOpts = Object.assign({}, opts.replyOpts, { | ||
| const replyOpts = Object.assign({}, opts.replyOptions, { |
There was a problem hiding this comment.
I think some fromOpts keys need to be moved (copied) to replyOpts.
Eg. in replyOptions type there's no maxRetriesOn503 (vice versa to retriesCount) -> those options are located on "global" options level.
But then in fastify/reply-from is expected to be on the same level: https://github.com/fastify/fastify-reply-from/blob/cd2ba083e4a4e8085dc973edb8c5e622efaf830e/index.js#L68
const onResponse = opts.onResponse
const rewriteHeaders = opts.rewriteHeaders || headersNoOp
const rewriteRequestHeaders = opts.rewriteRequestHeaders || requestHeadersNoOp
const getUpstream = opts.getUpstream || upstreamNoOp
const onError = opts.onError || onErrorDefault
const retriesCount = opts.retriesCount || 0
const maxRetriesOn503 = opts.maxRetriesOn503 || 10
When maxRetriesOn503 is not part of FastifyReplyFromHooks.
Therefore maxRetriesOn503 from fromOpts will never be effective.
I believe this will fix my issue here: #33
As far as I can tell this just breaks because the wrong variable is used in the
Object.assignlet me know if this seems valid. Tests passed locally for me.If you need any changes let me know.