goldilocks.js/app.js

24 lines
633 B
JavaScript
Raw Normal View History

2015-06-24 21:36:17 +00:00
'use strict';
module.exports = function (opts) {
var finalhandler = require('finalhandler');
var serveStatic = require('serve-static');
var serveIndex = require('serve-index');
var serve = serveStatic(opts.public);
var index = serveIndex(opts.public);
2015-06-30 23:11:01 +00:00
var content = opts.content;
2015-06-24 21:36:17 +00:00
return function (req, res) {
2015-06-30 23:11:01 +00:00
if (content && '/' === req.url) {
// res.setHeader('Content-Type', 'application/octet-stream');
res.end(content);
return;
}
2015-06-24 21:36:17 +00:00
var done = finalhandler(req, res);
serve(req, res, function (err) {
if (err) { return done(err); }
index(req, res, done);
});
};
};