Skip to content
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

do a hacky workaround directly to the http-server package to fix… #569

Merged
merged 3 commits into from
Nov 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lib/http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,33 @@ var fs = require('fs'),
auth = require('basic-auth'),
httpProxy = require('http-proxy'),
corser = require('corser'),
path = require('path'),
secureCompare = require('secure-compare');

// a hacky and direct workaround to fix https://github.com/http-party/http-server/issues/525
function getCaller() {
try {
var stack = new Error().stack;
var stackLines = stack.split('\n');
var callerStack = stackLines[3];
return callerStack.match(/at (.+) \(/)[1];
}
catch (error) {
return '';
}
}

var _pathNormalize = path.normalize;
path.normalize = function (p) {
var caller = getCaller();
var result = _pathNormalize(p);
// https://github.com/jfhbrook/node-ecstatic/blob/master/lib/ecstatic.js#L20
if (caller === 'decodePathname') {
result = result.replace(/\\/g, '/');
}
return result;
};

//
// Remark: backwards compatibility for previous
// case convention of HTTP
Expand Down