-
-
Notifications
You must be signed in to change notification settings - Fork 98
Transform HTML body before to send back to the proxied website #85
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
Comments
You need to provide the new payload as 2nd parameter in the |
I tried using done to return the new payload but this is actually where I can't see why it is not working as expected. The page will be blank:
|
@Eomm Note that right before the done a console.log will show the new payload without any issues. |
@Eomm I think the problem I am having is how to get the new payload once done() is called. I want to get it from the API endpoint:
|
Your code seems ok, we should check if this is a bug managing the streams Would you like to give it a shot? |
@Eomm Sure thing, I let you know how it goes. |
It appears to me that whenever I am trying to pass some parameters in the done() method, the browser won't render the proxied web app. I am not yet entirely sure how this is happening, but it could be a potential bug to fix. Have you got any luck with your failing tests? |
I understood that you were glad to work on it so I didn't allocate time 😅 |
No worries, I'm still on it anyway. So far I have it working very well without using fastify-http-proxy middleware. It's good for progressing on my project but not helpful for that specific issue. Basically I'm just using http-proxy and it is works fine. This let me think that we may have a bug to fix and I will try to find out more in the upcoming days. |
It appears to me that this issue has nothing to do with fastify-http-proxy plugin. Basically my proxied connection just hang up due to wrong order of middleware usage. The issue that I have is very similar to this one described here: http-party/node-http-proxy#180 (comment) I suggest to close the ticket for now and will open another one if I feel like there is a proper bug we need to fix. Also as a separate comment, it looks like node-http-proxy dies a lot and it is not reliable. Would like to see an example of production usage of fastify-http-proxy, I may have to consider doing my reverse-proxy server in Java instead. Thanks for your help. |
Please provide supporting evidence for such statements and list versions being used. There are plenty of us using this in production without issue. |
@jsumners Agreed with you, it was my very personal opinion here, while going through Stackoverflow and Googling around, I found different issues mentioning the one that I raised, where node-http-proxy dies after multiple runs. Most of the time it is related to bad usage (Having wrong order of middleware), so I am not saying this is unusable but quite tricky to get it right. |
fastify-http-proxy and node-http-proxy are two seperate modules. |
@jsumners I'm pretty sure there is lot of usage of fastify-http-proxy middleware, I was more asking for a solid example of usage in production. |
@mcollina Yes, I was originally commenting about node-http-proxy, not fastify-http-proxy. |
@mcollina To be more explicit, using an HTTP proxy is not only for solving CORS issue or just for the sake of proxying an external URL. A common case is to modify the body at the end and I did not succeed with node-http-proxy package. (It works but again it dies after multiple runs). I think it would be great to have a working example of modifying the body, somewhere in the documentation of fastify-http-proxy. If I get it to work, I will be happy to push a PR. Note that node-http-proxy does have an example of modifying the body. |
I'd like to see supporting evidence of that as well. A proxy is meant to facilitate communication between two systems. That can mean altering the metadata around the communication (e.g. HTTP headers), but that does not imply the content has been changed. |
@jsumners Well, I've got a requirement to inject custom JavaScript in any web app (A lot of testing framework do that to inject selenium drivers for example, ..). I went with the approach of using a reverse-proxy since there is not a thousand solution to that problem and the injection works pretty well. Not entirely sure what kind of "supporting evidence" you are looking for here? |
@jsumners Please read "Page proxying" section: https://devexpress.github.io/testcafe/documentation/how-it-works/ They use nodeJS to reverse proxy the web app under test and inject their own JS for automation. |
I'm using So for sure, we could improve this module by adding new features like:
|
@Eomm Thanks for sharing, it is useful, will have a look at it. And yes, I strongly think we could improve this feature of modifying body output, this is a common case for node http proxy middleware. |
I am trying to proxy any website, do some changes on the returned HTML string from the proxied website and then return it to the Browser. This is how far I've got:
You can see that I am adding my-custom.js script inside the BODY tag once I have unzipped and parsed the returned payload. It is working fine, however, the last bit I can't find yet is: How to return the transformed HTML string to the browser?
I have an API responsible for starting the Proxy server:
The text was updated successfully, but these errors were encountered: