diff options
Diffstat (limited to 'server.js')
-rwxr-xr-x | server.js | 7 |
1 files changed, 3 insertions, 4 deletions
@@ -38,6 +38,7 @@ function getSettings(req, res, next) { | |||
38 | } | 38 | } |
39 | 39 | ||
40 | function setSettings(req, res, next) { | 40 | function 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 | ||
61 | if (typeof config.folderListingEnabled === 'undefined') config.folderListingEnabled = true; | 62 | if (typeof config.folderListingEnabled === 'undefined') config.folderListingEnabled = false; |
62 | 63 | ||
63 | function isRoot(p) { | 64 | function 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")); | |||
150 | app.use('/tar', sendArchive("tar")); | 151 | app.use('/tar', sendArchive("tar")); |
151 | app.use('/', express.static(ROOT_FOLDER)); | 152 | app.use('/', express.static(ROOT_FOLDER)); |
152 | app.use('/', function welcomePage(req, res, next) { | 153 | app.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 | }); |
156 | app.use('/', function (req, res) { | 157 | app.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'); |