Skip to content
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

Question - Using replyOptions #33

Closed
thejones opened this issue Jan 9, 2019 · 4 comments
Closed

Question - Using replyOptions #33

thejones opened this issue Jan 9, 2019 · 4 comments

Comments

@thejones
Copy link
Contributor

thejones commented Jan 9, 2019

I have a general question on how to call, if possible, the onResponse method from reply-from when using http-proxy. I am successful in calling rewriteHeaders but have not had luck with the onResponse call.

I am testing with an app generated with fastify-cli.

This is what I have.

  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: (res) => {
        console.log('here'); // Should this work? Nothing is logged at this point.
      },
    },
  });

I have tried a few iterations but wanted to know if this is a supported and (most likely) a syntax error.

I did post this in Gitter as well but my timing seems to be a bit off of when others are online (not trying to spam two places).

Any help is appreciated.

@mcollina
Copy link
Member

mcollina commented Jan 9, 2019

That's passed as-is to fastify-reply-from (https://github.com/fastify/fastify-http-proxy/blob/master/index.js#L49). Does that option work if fastify-reply-from?

@thejones
Copy link
Contributor Author

Thanks @mcollina for the response. Yes, fastify-reply-from when called directly does work. The same route is called in both cases with the dame options, etc. I might have some time to look into this today but if you have any suggestions please let me know.

@mcollina
Copy link
Member

I've got no idea really

@thejones
Copy link
Contributor Author

No worries! I will dig in and report back what I find. Appreciate the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants