アプリケーションの外部で呼び出しを行うためのレスト クライアントを作成しました。残りの呼び出しから受信したデータをクライアントの Web ブラウザーに送信したいと考えています。
次のようなものですが、できるだけ疎結合で Web ブラウザーに書き戻すための応答へのアクセスを許可するコードを構成する最良の方法は何ですか? リクエスト ハンドラ内で残りのクライアントを定義したくありません。
var servReq = http.request(options, function(restResponse){
var status = restResponse.statusCode
var headers = restResponse.headers
restResponse.setEncoding("utf8");
d='';
restResponse.on('data', function(chunk){
d += chunk;
})
restResponse.on('end', function(restResponse){
// res would be a response to write back to the client's web browser
// with the data received from the rest client.
res.writeHead(200, {"content-type":"text/plain"})
res.write(d)
res.end();
})
}