Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How can I serve some URLs from express.js by making requests to another web application?

How can I serve some URLs from express.js by making requests to another web application?

Problem

I have written some code using express.js which I'd like to put on the same HTTP port as a Web Application implemented with another technology (in this case, Django). I don't want to have to redirect user browsers to another port since if I do they might bookmark URLs with the other port, and then I lose the ability to reconfigure the arrangements later. So, I'd like express.js to serve HTTP on its port, fulfilling some paths I specify by making HTTP requests to a secondary web application which is being served on another port.

Is there any middleware or other technique for express.js which will serve certain paths by making HTTP requests to other servers?

(The stackoverflow question How to make web service calls in Expressjs? is relevant but only discusses GET and I will have some POST requests to forward.)

Problem courtesy of: Dickon Reed

Solution

With node-http-proxy only a single call to app.use is required to reverse proxy all unhandled requests, like this:

var app = express.createServer();
# my app.get bindings
app.use(require('http-proxy').createServer(80, 'other-server-address'));
app.listen(80);
Solution courtesy of: Dickon Reed

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

How can I serve some URLs from express.js by making requests to another web application?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×