node.js - Using nodejs server with request package and function pipe()? -


i'm using nodejs server mockup backend @ moment. server webserver , returns json objects on different requests, works flawlessy. have json objects domain, have proxy server. have found package called request in npm. can simple example work, have forward whole webpage.

my code proxy looks this:

var $express = require('express'), $http = require('http'), $request = require('request'), $url = require('url'), $path = require('path'), $util = require('util'), $mime = require('mime');  var app = $express();  app.configure(function(){   app.set('port', process.env.port || 9090);   app.use($express.bodyparser());   app.use($express.methodoverride());    app.use('/', function(req, res){     var apiurl = 'http://localhost:9091';     console.log(apiurl);     var url = apiurl + req.url;     req.pipe($request(url).pipe(res));   });   });  $http.createserver(app).listen(app.get('port'), function () {   console.log("express server listening on port " + app.get('port'));    if (process.argv.length > 2 && process.argv.indexof('-open') > -1) {     var open = require("open");     open('http://localhost:' + app.get('port') + '/', function (error) {       if (error !== null) {         console.log("unable lauch application in browser. please install 'firefox' or 'chrome'");       }     });   } }) 

i'm loggin real server , acting correctly, can track response, body empty. want pass through whole website nodejs server through request.pipe function. ideas?

since in node.js, a.pipe(b) returns b (see documentation), code equivalent this:

// req.pipe($request(url).pipe(res)) // equivalent $request(url).pipe(res); req.pipe(res); 

as want proxy there no need pipe req res (and here doesn't make sense pipe multiple readable streams 1 writable stream), keep , proxy work:

$request(url).pipe(res); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -