-
Notifications
You must be signed in to change notification settings - Fork 2
/
compy-helper.js
39 lines (34 loc) · 1.14 KB
/
compy-helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var connect = require('connect');
var async = require('async');
var path = require('path');
var config = require(__dirname + '/config.json');
var _ = require('underscore');
var folderMount = function folderMount(point) {
return connect.static(path.resolve(point));
};
var folderDir = function folderDir(point){
return connect.directory(path.resolve(point));
}
module.exports = {
middleware: function(buildDir, opts){
options = {
livereload : true,
serveStatic : true,
serveDir : true,
middleware: []
}
var livereload = require('connect-livereload')({
port : config.livereloadPort
});
var serveStatic = folderMount(buildDir);
var serveDir = folderDir(buildDir);
return function(req, res, next){
var middlewares = [];
if(options.livereload) middlewares.push(async.apply(livereload, req, res));
if(options.serveStatic) middlewares.push(async.apply(serveStatic, req, res));
if(options.serveDir) middlewares.push(async.apply(serveDir, req, res));
if(options.middleware) middlewares = middlewares.concat(options.middleware);
async.series(middlewares,next);
}
}
}