aboutsummaryrefslogtreecommitdiffhomepage
path: root/server.js
diff options
context:
space:
mode:
Diffstat (limited to 'server.js')
-rwxr-xr-xserver.js7
1 files changed, 3 insertions, 4 deletions
diff --git a/server.js b/server.js
index bee74c7..c17fcb8 100755
--- a/server.js
+++ b/server.js
@@ -38,6 +38,7 @@ function getSettings(req, res, next) {
38} 38}
39 39
40function setSettings(req, res, next) { 40function setSettings(req, res, next) {
41 return next(new HttpError(400, 'not editable'));
41 if (typeof req.body.folderListingEnabled === 'undefined') return next(new HttpError(400, 'missing folderListingEnabled boolean')); 42 if (typeof req.body.folderListingEnabled === 'undefined') return next(new HttpError(400, 'missing folderListingEnabled boolean'));
42 43
43 config.folderListingEnabled = !!req.body.folderListingEnabled; 44 config.folderListingEnabled = !!req.body.folderListingEnabled;
@@ -58,7 +59,7 @@ try {
58 else console.log(`Cannot load config file ${CONFIG_FILE}`, e); 59 else console.log(`Cannot load config file ${CONFIG_FILE}`, e);
59} 60}
60 61
61if (typeof config.folderListingEnabled === 'undefined') config.folderListingEnabled = true; 62if (typeof config.folderListingEnabled === 'undefined') config.folderListingEnabled = false;
62 63
63function isRoot(p) { 64function isRoot(p) {
64 return path.join(ROOT_FOLDER, p) === path.join(ROOT_FOLDER, '/'); 65 return path.join(ROOT_FOLDER, p) === path.join(ROOT_FOLDER, '/');
@@ -150,12 +151,10 @@ app.use('/zip', sendArchive("zip"));
150app.use('/tar', sendArchive("tar")); 151app.use('/tar', sendArchive("tar"));
151app.use('/', express.static(ROOT_FOLDER)); 152app.use('/', express.static(ROOT_FOLDER));
152app.use('/', function welcomePage(req, res, next) { 153app.use('/', function welcomePage(req, res, next) {
153 if (config.folderListingEnabled || req.path !== '/') return next(); 154 if (config.folderListingEnabled || !isRoot(req.path)) return next();
154 res.status(200).sendFile(path.join(__dirname, '/frontend/welcome.html')); 155 res.status(200).sendFile(path.join(__dirname, '/frontend/welcome.html'));
155}); 156});
156app.use('/', function (req, res) { 157app.use('/', function (req, res) {
157 if (!config.folderListingEnabled) return res.status(404).sendFile(__dirname + '/frontend/404.html');
158
159 if (!fs.existsSync(path.join(ROOT_FOLDER, req.path))) return res.status(404).sendFile(__dirname + '/frontend/404.html'); 158 if (!fs.existsSync(path.join(ROOT_FOLDER, req.path))) return res.status(404).sendFile(__dirname + '/frontend/404.html');
160 159
161 res.status(200).sendFile(__dirname + '/frontend/public.html'); 160 res.status(200).sendFile(__dirname + '/frontend/public.html');