익스프레스 js 및 mikeal/request 라이브러리를 사용하여 간단한 프록시를 작성하려고합니다.
클라이언트 측 앱은 특정 경로 (/ api)에서 expressjs를 호출하고 모든 요청이 전달됩니다 원격 기계.
작동하지 않습니다. 분명히 뭔가 빠져 있어야합니다.익스프레스 및 마이클/요청 라이브러리가있는 노드 프록시
expressjs 코드 :
Forwarding to api http://xxx.xxx.xxx/account
PUT /api/account 200 120005ms
Forwarding to api http://xxx.xxx.xxx/account
PUT /api/account 200 120006ms
그리고 원격 API에, 아파치 로그 요청이 만들어진 것을 보여 :
app.use('/api', function(req, res) {
var url = config.api + req.url;
var auth = authlib.createTokenHeader(req.user) || {};
var forwarded = { 'X-Forwarded-For': req.connection.remoteAddress };
console.log('Forwarding to api ' + url);
req.pipe(request({
uri:url,
headers: _.merge(authlib.stripSensitiveHeaders(req.headers), auth, forwarded),
})).pipe(res);
});
http://localhost:9000/api/account
에 PUT 요청을 발행, 꿀꿀 로그를 보여줍니다
xx.xx.xx.xx - - [23/Feb/2014:17:44:23 +0000] "PUT /account HTTP/1.1" 400 189 "http://localhost:9000/login" "Mozilla/5.0"
xx.xx.xx.xx - - [23/Feb/2014:17:46:23 +0000] "PUT /account HTTP/1.1" 400 189 "http://localhost:9000/login" "Mozilla/5.0"
결국 Chrome은 빈 응답이 수신되었음을 알립니다 :
PUT http://localhost:9000/api/account net::ERR_EMPTY_RESPONSE
질문에 두 가지 요청이 있는데 왜 120s 시간 초과가 발생합니까?
나는 더 간단 그것을 만들려고했지만, 결과는 동일합니다
app.use('/api', function(req, res) {
req.pipe(request(config.api + req.url)).pipe(res);
});
그리고 내가 http://xxx.xxx.xxx/account 엔드 포인트에 동일한 컴퓨터에 크롬에서 우편 배달 같은 것을 사용하여 게시 할 경우 작동