From 04c7647687a756f90e683b7fdfaf1a29d3c02c97 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Mon, 13 Feb 2017 08:50:51 +0000 Subject: [PATCH] Add opt-in dir listing --- package.json | 1 + src/consts.js | 1 + src/server.js | 11 ++++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 1cb94d0..de901b9 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "express-winston": "=2.1.2", "helmet": "=3.4.0", "opbeat": "=4.7.0", + "serve-index": "=1.8.0", "winston": "=2.3.0" }, "devDependencies": { diff --git a/src/consts.js b/src/consts.js index e38eb6d..a8d59ce 100644 --- a/src/consts.js +++ b/src/consts.js @@ -5,5 +5,6 @@ module.exports = { PORT: process.env.PORT || 5000, IN_TEST, IN_PRODUCTION: process.env.NODE_ENV === 'production', + DIR_LIST: process.env.DIR_LIST, BASIC_AUTH_ENABLED: process.env.BASIC_AUTH_USERNAME && process.env.BASIC_AUTH_PASSWORD }; diff --git a/src/server.js b/src/server.js index 51e8a88..4013ab5 100755 --- a/src/server.js +++ b/src/server.js @@ -7,6 +7,7 @@ const consts = require('./consts'); const compression = require('compression'); const helmet = require('helmet'); +const serveIndex = require('serve-index'); const opbeat = require('opbeat').start({ active: consts.IN_PRODUCTION }); @@ -19,7 +20,15 @@ const basicAuth = require('./basic-auth'); // Custom Middleware app.use(logging); app.use(basicAuth); -app.use(staticFiles.indexHandle); + +if (consts.DIR_LIST) { + app.use(serveIndex(consts.SERVE_DIR, { + icons: true + })); +} else { + app.use(staticFiles.indexHandle); +} + app.use(staticFiles.static); app.use(handle404);