forked from svrjs/svrjs
Fixed error handling for invalid URL rewrite regexes. Also fixed bug with HTTP proxy not working.
This commit is contained in:
parent
60a84d879d
commit
1a2019664a
1 changed files with 18 additions and 9 deletions
15
svr.js
15
svr.js
|
@ -4168,8 +4168,8 @@ if (!cluster.isPrimary) {
|
|||
// Handle URL rewriting
|
||||
function rewriteURL(address, map, callback, _fileState, _mapBegIndex) {
|
||||
var rewrittenURL = address;
|
||||
if (!isProxy) {
|
||||
var doCallback = true;
|
||||
if (!isProxy) {
|
||||
for (var i = (_mapBegIndex ? _mapBegIndex : 0); i < map.length; i++) {
|
||||
var mapEntry = map[i];
|
||||
if(href != "/" && (mapEntry.isNotDirectory || mapEntry.isNotFile) && !_fileState) {
|
||||
|
@ -4190,15 +4190,20 @@ if (!cluster.isPrimary) {
|
|||
break;
|
||||
}
|
||||
if (matchHostname(mapEntry.host) && createRegex(mapEntry.definingRegex).test(address) && !(mapEntry.isNotDirectory && _fileState == 2) && !(mapEntry.isNotFile && _fileState == 1)) {
|
||||
try {
|
||||
mapEntry.replacements.forEach(function (replacement) {
|
||||
rewrittenURL = rewrittenURL.replace(createRegex(replacement.regex), replacement.replacement);
|
||||
});
|
||||
if (mapEntry.append) rewrittenURL += mapEntry.append;
|
||||
} catch (err) {
|
||||
doCallback = false;
|
||||
callback(err, address);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(doCallback) callback(rewrittenURL);
|
||||
if(doCallback) callback(null, rewrittenURL);
|
||||
}
|
||||
|
||||
// Trailing slash redirection
|
||||
|
@ -4233,7 +4238,11 @@ if (!cluster.isPrimary) {
|
|||
var origHref = href;
|
||||
|
||||
// Rewrite URLs
|
||||
rewriteURL(req.url, rewriteMap, function(rewrittenURL) {
|
||||
rewriteURL(req.url, rewriteMap, function(err, rewrittenURL) {
|
||||
if (err) {
|
||||
callServerError(500, undefined, err);
|
||||
return;
|
||||
}
|
||||
if (rewrittenURL != req.url) {
|
||||
serverconsole.resmessage("URL rewritten: " + req.url + " => " + rewrittenURL);
|
||||
req.url = rewrittenURL;
|
||||
|
|
Reference in a new issue