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:
MICHAEL JACKSON 2017-08-22 18:51:37 -07:00
parent ab3e21b8f8
commit f64bb6bfd5
1 changed files with 1 additions and 4 deletions

View File

@ -75,15 +75,12 @@ function fetchFile(req, res, next) {
// Based on the URL, figure out which file they want. // Based on the URL, figure out which file they want.
const base = path.join(req.packageDir, req.filename) 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) if (error)
console.error(error) console.error(error)
if (file == null) { if (file == null) {
res.status(404).type('text').send(`Cannot find file "${req.filename}" in package ${req.packageSpec}`) 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 { } else {
req.file = file.replace(req.packageDir, '') req.file = file.replace(req.packageDir, '')
req.stats = stats req.stats = stats