Treat URLs with no trailing slashes like files
This is to be consistent with the rest of the API, but also to allow packages to omit the trailing slash and file name when publishing multiple builds in the same package.
This commit is contained in:
parent
ab3e21b8f8
commit
f64bb6bfd5
|
@ -75,15 +75,12 @@ function fetchFile(req, res, next) {
|
|||
// Based on the URL, figure out which file they want.
|
||||
const base = path.join(req.packageDir, req.filename)
|
||||
|
||||
findFile(base, false, function (error, file, stats) {
|
||||
findFile(base, req.filename[req.filename.length - 1] !== '/', function (error, file, stats) {
|
||||
if (error)
|
||||
console.error(error)
|
||||
|
||||
if (file == null) {
|
||||
res.status(404).type('text').send(`Cannot find file "${req.filename}" in package ${req.packageSpec}`)
|
||||
} else if (stats.isDirectory() && req.pathname[req.pathname.length - 1] !== '/') {
|
||||
// Append / to directory URLs.
|
||||
res.status(301).redirect(`${req.pathname}/${req.search}`)
|
||||
} else {
|
||||
req.file = file.replace(req.packageDir, '')
|
||||
req.stats = stats
|
||||
|
|
Loading…
Reference in New Issue