From f64bb6bfd574776caa6c2f08ed39d6dd31363fde Mon Sep 17 00:00:00 2001 From: MICHAEL JACKSON Date: Tue, 22 Aug 2017 18:51:37 -0700 Subject: [PATCH] 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. --- server/middleware/fetchFile.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/server/middleware/fetchFile.js b/server/middleware/fetchFile.js index 1d5c873..ba3ad2e 100644 --- a/server/middleware/fetchFile.js +++ b/server/middleware/fetchFile.js @@ -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