Skip to content

Instantly share code, notes, and snippets.

@halfdan
Last active August 29, 2015 13:56
Show Gist options
  • Save halfdan/9261294 to your computer and use it in GitHub Desktop.
Save halfdan/9261294 to your computer and use it in GitHub Desktop.
var express = require('express'),
app = express(),
hb = require('express3-handlebars'),
fs = require('fs');
var configurationFile = 'config.json';
var configuration = JSON.parse (fs.readFileSync(configurationFile));
function createFilelist (callback) {
fs.readdir(configuration.filepath, function (err, files) {
callback(err, files.map(function(item) { return '/files/' + item; }));
});
};
app.engine('handlebars', hb({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');
app.get('/', function (req, res) {
createFilelist(function(err, fileList) {
// ToDo: Check for err
res.render('filelist', {
showTitle: true,
flist: fileList,
});
});
});
var path = '/' + configuration.filepath;
app.use('/files', express.static(__dirname + path));
app.listen(configuration.webport);
console.log('Listening on port ' +configuration.webport);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment