lib/bundler.js
function(moduleRegex) {
        var self = this;

        moduleRegex = moduleRegex || /^(.+)\.js$/;

        return function(req, res, next) {
            var match = req.url.match(moduleRegex);
            if(!match) return next();

            var module= match[1];

            self.bundle(module, function(err, src) {
                res.setHeader('Content-Type', 'text/javascript; charset=utf-8');
                res.setHeader('Cache-Control', 'no-cache');

                // expose event to allow for custom headers
                self.emit('pre-response', err, res, module, src);

                res.send(src);
            });
        };
    }
function(moduleRegex) {
        var self = this;

        moduleRegex = moduleRegex || /^(.+)\.js$/;

        return function(req, res, next) {
            var match = req.url.match(moduleRegex);
            if(!match) return next();

            var module= match[1];

            self.bundle(module, function(err, src) {
                res.setHeader('Content-Type', 'text/javascript; charset=utf-8');
                res.setHeader('Cache-Control', 'no-cache');

                // expose event to allow for custom headers
                self.emit('pre-response', err, res, module, src);

                res.send(src);
            });
        };
    }
function ( moduleRegex ) { var self = this ; moduleRegex = moduleRegex || / ^(.+)\.js$ / ; return function ( req , res , next ) { var match = req . url . match ( moduleRegex ) ; if ( ! match ) return next ( ) ; var module = match [ 1 ] ; self . bundle ( module , function ( err , src ) { res . setHeader ( 'Content-Type' , 'text/javascript; charset=utf-8' ) ; res . setHeader ( 'Cache-Control' , 'no-cache' ) ; // expose event to allow for custom headers self . emit ( 'pre-response' , err , res , module , src ) ; res . send ( src ) ; } ) ; } ; }
Generate a middeware function + moduleRegex - regex - used to match urls - requires the first capture group to be the module
Generate a middeware function + moduleRegex - regex - used to match urls - requires the first capture group to be the module