fix hns redirects

This commit is contained in:
Karol Wypchlo 2020-07-31 15:15:55 +02:00
parent 615623f962
commit e663eebc9e
1 changed files with 4 additions and 6 deletions

View File

@ -85,14 +85,12 @@ server.use(
const basepath = url.resolve("/", skylink); // make the url absolute
const subpath = req.url.slice(1); // drop the leading slash
// if the skylink from handshake does not contain a subpath but subpath
// is defined in request, join the skylink and subpath together (do not
// use url.resolve because it will replace skylink with subapth thinking
// it is relative)
if (skylink.length === 46 && subpath) {
return `${basepath}/${subpath}`;
// if the record is just a raw skylink, replace baseUrl with /skylink
if (skylink.length === 46) {
return req.originalUrl.replace(req.baseUrl, basepath);
}
// if the record contains more than a skylink then it needs to be resolved
return url.resolve(basepath, subpath);
},
})