]> git.immae.eu Git - perso/Immae/Projets/Nodejs/Surfer.git/blobdiff - src/files.js
Use 222 status code to indicate folder listing and use stdout only for data
[perso/Immae/Projets/Nodejs/Surfer.git] / src / files.js
index 3b28d3ff31d6e3fd6378338001df8c9bd34f9dd9..d12782d8c001f5fceefe1b151b1214ce3f13dd94 100644 (file)
@@ -54,7 +54,7 @@ function copyFile(source, target, cb) {
 }
 
 function getAbsolutePath(filePath) {
-    var absoluteFilePath = path.resolve(gBasePath, filePath);
+    var absoluteFilePath = path.resolve(path.join(gBasePath, filePath));
 
     if (absoluteFilePath.indexOf(gBasePath) !== 0) return null;
     return absoluteFilePath;
@@ -71,7 +71,7 @@ function get(req, res, next) {
         debug('get', absoluteFilePath);
 
         if (result.isFile()) return res.sendFile(absoluteFilePath);
-        if (result.isDirectory()) return res.status(200).send({ entries: fs.readdirSync(absoluteFilePath) });
+        if (result.isDirectory()) return res.status(222).send({ entries: fs.readdirSync(absoluteFilePath) });
 
         return next(new HttpError(500, 'unsupported type'));
     });