-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add notFound function to set respondNotFound callback (#44) #54
Changes from all commits
e0b1f64
6a219df
2721b6c
d364acc
97f27c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,7 +86,7 @@ function ReverseProxy(opts){ | |
proxy.web(req, res, {target: target}); | ||
} | ||
}else{ | ||
notFound(res); | ||
respondNotFound(req, res); | ||
} | ||
}); | ||
|
||
|
@@ -138,7 +138,7 @@ function ReverseProxy(opts){ | |
if(target){ | ||
proxy.web(req, res, {target: target}); | ||
}else{ | ||
notFound(res); | ||
respondNotFound(req, res); | ||
} | ||
}); | ||
|
||
|
@@ -174,7 +174,7 @@ function ReverseProxy(opts){ | |
if(target){ | ||
proxy.ws(req, socket, head, {target: target}); | ||
}else{ | ||
notFound(socket); | ||
respondNotFound(req, socket); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't an HTTP response object, but does a socket have the same set of properties and methods as an HTTP response? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it has the write and the end, I am not sure of the status method, probably not. I think that this codepath never happens in practice though, thats why it has been working so far. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if it would be valid anyway to attempt to send a "not found" over a socket. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thats what I meant in my previous comment :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :P |
||
} | ||
} | ||
|
||
|
@@ -417,11 +417,18 @@ function getSource(req){ | |
} | ||
*/ | ||
|
||
function notFound(res){ | ||
var respondNotFound = function(req, res){ | ||
res.statusCode = 404; | ||
res.write('Not Found'); | ||
res.end(); | ||
} | ||
}; | ||
|
||
ReverseProxy.prototype.notFound = function(callback){ | ||
if(typeof callback == "function") | ||
respondNotFound = callback; | ||
else | ||
throw Error('notFound callback is not a function'); | ||
}; | ||
|
||
// | ||
// Redirect to the HTTPS proxy | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kind of made up this formatting for documenting a parameter that's a callback. Not sure if there's a standard for this or anything.