diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2020-05-05 01:18:19 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2020-05-05 02:17:44 +0200 |
commit | ca2fe6ecc5142115ba163875ccce2d0947ee50dc (patch) | |
tree | 39afce46278898e4161a0f63e0f2353145db9b27 | |
parent | 693472d06c52340e85ee4bdf066fc0d746398f43 (diff) | |
download | Surfer-ca2fe6ecc5142115ba163875ccce2d0947ee50dc.tar.gz Surfer-ca2fe6ecc5142115ba163875ccce2d0947ee50dc.tar.zst Surfer-ca2fe6ecc5142115ba163875ccce2d0947ee50dc.zip |
Make configuration not editable
-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'); |