]> git.immae.eu Git - perso/Immae/Projets/Nodejs/Surfer.git/blobdiff - server.js
Make listen port and ldap filter more flexible
[perso/Immae/Projets/Nodejs/Surfer.git] / server.js
index bee74c7ee5e71b500e6db60b36d20b898c94d40b..e79dad29e444f652477bba8fe20af6e94afac793 100755 (executable)
--- a/server.js
+++ b/server.js
@@ -38,6 +38,7 @@ function getSettings(req, res, next) {
 }
 
 function setSettings(req, res, next) {
+    return next(new HttpError(400, 'not editable'));
     if (typeof req.body.folderListingEnabled === 'undefined') return next(new HttpError(400, 'missing folderListingEnabled boolean'));
 
     config.folderListingEnabled = !!req.body.folderListingEnabled;
@@ -58,7 +59,7 @@ try {
     else console.log(`Cannot load config file ${CONFIG_FILE}`, e);
 }
 
-if (typeof config.folderListingEnabled === 'undefined') config.folderListingEnabled = true;
+if (typeof config.folderListingEnabled === 'undefined') config.folderListingEnabled = false;
 
 function isRoot(p) {
   return path.join(ROOT_FOLDER, p) === path.join(ROOT_FOLDER, '/');
@@ -150,19 +151,17 @@ app.use('/zip', sendArchive("zip"));
 app.use('/tar', sendArchive("tar"));
 app.use('/', express.static(ROOT_FOLDER));
 app.use('/', function welcomePage(req, res, next) {
-    if (config.folderListingEnabled || req.path !== '/') return next();
+    if (config.folderListingEnabled || !isRoot(req.path)) return next();
     res.status(200).sendFile(path.join(__dirname, '/frontend/welcome.html'));
 });
 app.use('/', function (req, res) {
-    if (!config.folderListingEnabled) return res.status(404).sendFile(__dirname + '/frontend/404.html');
-
     if (!fs.existsSync(path.join(ROOT_FOLDER, req.path))) return res.status(404).sendFile(__dirname + '/frontend/404.html');
 
     res.status(200).sendFile(__dirname + '/frontend/public.html');
 });
 app.use(lastMile());
 
-var server = app.listen(3000, function () {
+var server = app.listen(process.env.LISTEN, function () {
     var host = server.address().address;
     var port = server.address().port;