Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Node JS to proxy http and modify response

I'm trying to write a front end to an API service with Node JS.

I'd like to be able to have a user point their browser at my node server and make a request. The node script would modify the input to the request, call the api service, then modify the output and pass back to the user.

I like the solution here (with Express JS and node-http-proxy) as it passes the cookies and headers directly from the user through my site to the api server.

proxy request in node.js / express

I see how to modify the input to the request, but i can't figure out how to modify the response. Any suggestions?

like image 755
Will Glass Avatar asked Nov 28 '12 02:11

Will Glass


People also ask

What is node http-proxy?

node-http-proxy is an HTTP programmable proxying library that supports websockets. It is suitable for implementing components such as reverse proxies and load balancers.

How does HTTP request work in node JS?

The HTTP POST method sends data to the server. The type of the body of the request is indicated by the Content-Type header. We use Express. js in order to create a server and to make requests (GET, POST, etc).


1 Answers

transformer-proxy could be useful here. I'm the author of this plugin and I'm answering here because I found this page when looking for the same question and wasn't satisfied with harmon as I don't want to manipulate HTML.

Maybe someone else is looking for this and finds it useful.

like image 188
Philipp Avatar answered Oct 01 '22 04:10

Philipp