저는 Node.js의 상대적으로 초보자입니다. Node.js에서 요청 본문을 수정 한 다음 전달하려고하는 이틀이 지났습니다. 프록시의 경우 http-proxy
모듈을 사용하고 있습니다.요청 본문을 수정 한 다음 Node.js에서 프록시합니다.
내가해야 할 일은 JSON 객체 내부의 사용자 비밀번호를 가로 채서 암호화하고 요청 본문 내에 새로운 암호화 된 비밀번호를 설정하는 것입니다.
문제는 요청 본문을 수집하려고 할 때마다 (즉, body-parser
을 사용하여) 소비한다는 것입니다. 이 작업을 어떻게 수행 할 수 있습니까? 나는 노드의 Request가 스트림을 가지고있는 것을 안다.
나는 완전성을 위해 express
을 사용하여 프록시 처리 전에 여러 작업을 연결합니다.
편집
의 I 프록시해야한다는 사실 요청이 쓸모가 없습니다. 그것은 내가 사용하려고하는 코드를 따른다. (스프링 MVC에 의해 나머지)
function encipher(req, res, next){
var password = req.body.password;
var encryptionData = Crypto().saltHashPassword(password);
req.body.password = encryptionData.passwordHash;
req.body['salt'] = encryptionData.salt;
next();
}
server.post("/users", bodyParser.json(), encipher, function(req, res) {
apiProxy.web(req, res, {target: apiUserForwardingUrl});
});
서버는 나에게 예외 Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: null
이렇게하면 '보낸 후 헤더를 설정할 수 없습니다.'오류가 발생합니다. Cf. https://github.com/nodejitsu/node-http-proxy/issues/1168 및 https://github.com/nodejitsu/node-http-proxy/issues/908. –