私は小規模なプロキシをnodejs、express、およびhtt-proxyで記述しました。中に思いついたエクスプレスプロキシルートを使用した応答がありません
var express = require('express'),
app = express.createServer(),
httpProxy = require('http-proxy');
app.use(express.bodyParser());
app.listen(process.env.PORT || 1235);
var proxy = new httpProxy.RoutingProxy();
app.get('/', function(req, res) {
res.sendfile(__dirname + '/index.html');
});
app.get('/js/*', function(req, res) {
res.sendfile(__dirname + req.url);
});
app.get('/css/*', function(req, res) {
res.sendfile(__dirname + req.url);
});
app.all('/*', function(req, res) {
req.url = 'v1/public/yql?q=show%20tables&format=json&callback=';
proxy.proxyRequest(req, res, {
host: 'query.yahooapis.com', //yahoo is just an example to verify its not the apis fault
port: 8080
});
});
問題は、ヤフーAPIからの応答がないということであるかもしれない応答があるが、私はいけない:それは、ローカルファイルを提供するためにうまく動作しますが、それは外部APIへのプロキシになると失敗しますブラウザ。
あなたは 'req.pipe(request(url))。pipe(res);'で何が起こるかを説明することができます。 2つの 'パイプ'が必要なのはなぜですか? – Jonathan
リクエストにjsonのcontent-typeがあると 'pipe'行がハングします - [この質問](http://stackoverflow.com/questions/26121830/proxy-json-requests-with-node-express) – Jonathan
上の 'request(url).pipe(res);'のみを使用して 'request(url).pipe(res);' [ここに示唆されている](http://stackoverflow.com/a/16924410/348545) – Jonathan