Code coverage report for browserify-middleware/lib/send.js

Statements: 100% (20 / 20)      Branches: 100% (17 / 17)      Functions: 100% (3 / 3)      Lines: 100% (18 / 18)      Ignored: 1 statement, 1 branch     

All files » browserify-middleware/lib/ » send.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    1 1 1   1 1 89 89 44   45 45 42 42 4   42       42 42 4   42        
'use strict';
 
var prepare = require('prepare-response');
var compile = require('./compile');
var start = new Date().toUTCString();
 
var cache = {};
module.exports = function send(path, options, req, res, next) {
  var cacheKey = JSON.stringify(path);
  if (options.cache && options.cache !== 'dynamic' && cache[cacheKey]) {
    return cache[cacheKey].send(req, res);
  }
  compile(path, options, function (err, src) {
    if (err) return next(err);
    var headers = {'content-type': 'application/javascript'};
    if (options.cache && options.cache !== 'dynamic') {
      headers['cache-control'] = options.cache;
    }
    prepare(src, headers, {
      gzip: options.gzip
    }).nodeify(function (err, response) {
      /* istanbul ignore if */
      Iif (err) return next(err);
      if (options.cache && options.cache !== 'dynamic') {
        cache[cacheKey] = response;
      }
      response.send(req, res);
    });
  });
}