-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.assign
let me know if this seems valid. Tests passed locally for me.If you need any changes let me know.