ノードが約 400K の json を返すネイティブ mongo rest api を使用してアプリのプロトタイプを作成しています。以下を使用して、mongo のネイティブ API にリクエストを送信し、結果を返します。
http.request(options, function(req)
{
req.on('data', function(data)
{
console.log(data,data.rows);
response.send( 200, data );
}
);
}
)
.on('error', function(error)
{
console.log('error\t',error);
response.send(500, error);
}
)
.end();
curl でヒットするhttp://localhost:8001/api/testdata
と、応答は適切です (からノードのコンソールに出力されるconsole.log
ものと、curl によって受信されるものの両方)。しかし、アプリで ajax 経由でヒットすると、ストリームが中断data
され、ノードのコンソール (ターミナル) に出力されても奇妙です: 複数の EOF があり、Chrome の開発ツールでの呼び出しに対する Network > 応答は最初の EOF で終了します.
もう1つの奇妙なこと:data
次のようになります:
{
"offset": 0,
"rows": [ … ]
}
しかし、ノードでもクライアント側(角度)でも data.rows を参照できません(未定義を返します)。typeof data
戻ります[object Object]
。
EDIT curl と angular の両方のリクエスト ヘッダー (Node によって報告される) は次のとおりです。
req.headers: {
'x-action': '',
'x-ns': 'test.headends',
'content-type': 'text/plain;charset=utf-8',
connection: 'close',
'content-length': '419585'
}
EDIT私はAngularとcurlの両方で直接(Nodeからではなく)応答ヘッダーをチェックしましたが、意見の相違があります(ノードからではなくcurlとangularの両方から直接同じ出力が得られました):
access-control-allow-headers: "Origin, X-Requested-With, Content-Type, Accept"
access-control-allow-methods: "OPTIONS,GET,POST,PUT,DELETE"
access-control-allow-origin: "*"
connection: "keep-alive"
content-length: "65401" // <---------------- too small!
content-type: "application/octet-stream"
// ^-- if i force "application/json"
// with response.json() instead of response.send() in Node,
// the client displays octets (and it takes 8s instead of 0s)
date: "Mon, 15 Jul 2013 18:36:50 GMT"
etag: ""-207110537""
x-powered-by: "Express"