Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var path = require('path');
var enableMiddlewareShorthand = require('./enableMiddlewareShorthand');

module.exports = function(options) {

var defaults = {

/**
Expand Down Expand Up @@ -46,7 +46,7 @@ module.exports = function(options) {
},

// Middleware: Directory listing
// For possible options, see:
// For possible options, see:
// https://github.com/expressjs/serve-index
directoryListing: {
enable: false,
Expand Down Expand Up @@ -82,23 +82,11 @@ module.exports = function(options) {
}

// Create server
var stream = through.obj(function(file, enc, callback) {
var files = [];

var stream = through.obj(function(file, enc, callback) {
app.use(serveStatic(file.path));

if (config.fallback) {

var fallbackFile = file.path + '/' + config.fallback;

if (fs.existsSync(fallbackFile)) {

app.use(function(req, res) {
fs.createReadStream(fallbackFile).pipe(res);
});

}
}

if (config.livereload.enable) {

watch(file.path, function(filename) {
Expand All @@ -119,6 +107,24 @@ module.exports = function(options) {

});

stream.on('data', function(file) {
files.push(file)
});

stream.on('end', function() {
if (config.fallback) {
files.forEach(function(file){
var fallbackFile = file.path + '/' + config.fallback;

if (fs.existsSync(fallbackFile)) {
app.use(function(req, res) {
fs.createReadStream(fallbackFile).pipe(res);
});
}
});
}
});

var webserver = http.createServer(app).listen(config.port, config.host);

gutil.log('Webserver started at', gutil.colors.cyan('http://' + config.host + ':' + config.port));
Expand Down