hoxy
hoxy copied to clipboard
What if the server response timeOut or 404
How to control the server timeOut or statusCode === 404 in the 'response' phase ??
You can check response.statusCode during the response phase.
I'm not getting any statusCode..... is their a timeOut setting to make it shorter. Or why am I not getting the statusCode ?
function responseInterceptor(request, response) {
console.log('+++++++++++++++++++ Response ++++++++++++++++++++');
console.log(arguments, response.statusCode); // < === Not getting 404 nor timeOut
console.log('+++++++++++++++++++++++++++++++++++++++++++++++++');
}
function requestInterceptor(request, response) {
// .........
}
function attachInterceptors() {
proxy.intercept({
phase: 'request',
as: 'json'
}, requestInterceptor);
proxy.intercept({
phase: 'response',
as: 'json'
}, responseInterceptor);
}
proxy = hoxy.createServer({
reverse: 'https://example.com/'
// tls: {
// key: fs.readFileSync('./my-server.key.pem'),
// cert: fs.readFileSync('./my-server.crt.pem')
// }
}).listen(5000);
attachInterceptors();
Is it logging undefined?
'1':
Response {
domain: null,
_events: { log: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
_data: { statusCode: 200, headers: {}, slow: {} },
phase: 'request' },
'2':
Cycle {
domain: null,
_events: { log: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
_proxy:
Proxy {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
_reverse: 'https://non-existing-example.com/',
_tls: undefined,
_intercepts: [Object],
_server: [Object] },
_request:
Request {
domain: null,
_events: [Object],
_eventsCount: 1,
_maxListeners: undefined,
_data: [Object],
_populated: true,
phase: 'request' },
_response:
Response {
domain: null,
_events: [Object],
_eventsCount: 1,
_maxListeners: undefined,
_data: [Object],
phase: 'request' },
_phase: 'request' } }
That looks incomplete. What does it log if you just do console.log(response.statusCode)?
Nothing is been logged. I've managed to resolve this issues by login in the 'response-sent' phase. Yeah, I've trim the request part of the argument cause I didn't tough it was usefull.
So if you intend to support the response.statusCode on response phase, then this issue isn't fixed, and I would gladdly provide you an example of it
But if you intend no to support it, and instead encorage user to use the response-sent phase, then you should make a note on documentation ;)
I would be more than happy to help you either ways, I think hoxy is amazing ;) !!! And you're very kind ^^
But specifically, when you say nothing was logged, do you mean it logged undefined, or was the console.log() statement never reached, or something else?
console.log() never reached, as if the timeOut is way to big, or something like that
The output pasted above looks like a fragment of arguments is being printed from console.log(arguments, response.statusCode). The status code should appear immediately after it. However it looks like you didn't paste the entire output, which is why I was asking.
So no logging the server's timeOut (waited my whole lunch, so about an hour or so )
This is my code
#!/usr/bin/env node
/*eslint no-unused-vars: 0*/
'use strict';
(function () {
var hoxy = require('hoxy'), proxy;
function responseSentInterceptor(request, response) {
console.log('====================== RESPONSE SENT INTERCEPTOR');
console.log(request, response);
}
function responseInterceptor(request, response) {
console.log('====================== RESPONSE INTERCEPTOR');
console.log(request, response);
}
function requestInterceptor(request, response) {
console.log('======================= REQUEST INTERCEPTOR');
console.log(request, response);
}
function attachInterceptors() {
proxy.intercept({
phase: 'request',
as: 'json'
}, requestInterceptor);
proxy.intercept({
phase: 'response',
as: 'json'
}, responseInterceptor);
proxy.intercept({
phase: 'response-sent'
}, responseSentInterceptor);
}
proxy = hoxy.createServer({
reverse: 'http://thisIsNot.a.real.server'
}).listen(5000);
attachInterceptors();
}());
Output
======================= REQUEST INTERCEPTOR
Request {
domain: null,
_events: { log: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
_data:
{ slow: {},
httpVersion: '1.1',
headers:
{ 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0',
accept: 'application/json, text/javascript',
'accept-language': 'en-US,es;q=0.8,en;q=0.5,es-ES;q=0.3',
'accept-encoding': 'gzip, deflate',
dnt: '1',
channel: '49',
version: '2',
'x-requested-with': 'XMLHttpRequest',
'content-type': 'application/json; charset=UTF-8',
referer: 'http://localhost:3000/',
'content-length': '268',
cookie: 'JSESSIONID=0000RWu-GDpXC4SsvFPvl5PFTkq:191dudcmv',
connection: 'keep-alive',
pragma: 'no-cache',
'cache-control': 'no-cache',
host: 'thisisnot.a.real.server' },
protocol: 'http:',
hostname: 'thisisnot.a.real.server',
method: 'POST',
url: '/auth/validate',
source:
JsonReader {
_readableState: [Object],
readable: true,
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
_obj: [Object] } },
_populated: true,
phase: 'request' } Response {
domain: null,
_events: { log: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
_data: { statusCode: 200, headers: {}, slow: {} },
phase: 'request' }
So I hope this clarify my issue =^.^=
And thanks again !! (:
Can you add
proxy.log('error warn debug', process.stderr);
proxy.log('info', process.stdout);
and let me know if it logs any errors or anything?