+
+var rootFolder = path.resolve(__dirname, process.argv[2] || 'files');
+var configFile = path.resolve(__dirname, process.argv[3] || '.config.json');
+
+// Ensure the root folder exists
+mkdirp.sync(rootFolder);
+
+var config = {
+ folderListingEnabled: true
+};
+
+function getSettings(req, res, next) {
+ res.send({ folderListingEnabled: !!config.folderListingEnabled });
+}
+
+function setSettings(req, res, next) {
+ if (typeof req.body.folderListingEnabled === 'undefined') return next(new HttpError(400, 'missing folderListingEnabled boolean'));
+
+ config.folderListingEnabled = !!req.body.folderListingEnabled;
+
+ fs.writeFile(configFile, JSON.stringify(config), function (error) {
+ if (error) return next(new HttpError(500, 'unable to save settings'));
+
+ next(new HttpSuccess(201, {}));
+ });
+}
+
+// Load the config file
+try {
+ config = require(configFile);
+} catch (e) {
+ if (e.code === 'MODULE_NOT_FOUND') console.log(`Config file ${configFile} not found`);
+ else console.log(`Cannot load config file ${configFile}`, e);
+}
+
+if (typeof config.folderListingEnabled === 'undefined') config.folderListingEnabled = true;
+
+// Setup the express server and routes