Sha256: 0e802a8d68c24639aae3a48e8559b37dde6db6a70970825ad28edadb9e64ab65

Contents?: true

Size: 1.73 KB

Versions: 17

Compression:

Stored size: 1.73 KB

Contents

/**
 * Source Files middleware is responsible for serving all the source files under the test.
 */

var querystring = require('querystring');
var common = require('./common');
var pause = require('connect').utils.pause;


var findByPath = function(files, path) {
  for (var i = 0; i < files.length; i++) {
    if (files[i].path === path) {
      return files[i];
    }
  }

  return null;
};


var createSourceFilesMiddleware = function(filesPromise, serveFile,
    /* config.basePath */ basePath) {

  return function(request, response, next) {
    // TODO(vojta): serve files under urlRoot (also update the formatError)
    var requestedFilePath = querystring.unescape(request.url)
        .replace(/\?.*$/, '')
        .replace(/^\/absolute/, '')
        .replace(/^\/base/, basePath);

    // Need to pause the request because of proxying, see:
    // https://groups.google.com/forum/#!topic/q-continuum/xr8znxc_K5E/discussion
    // TODO(vojta): remove once we don't care about Node 0.8
    var pausedRequest = pause(request);

    return filesPromise.then(function(files) {
      // TODO(vojta): change served to be a map rather then an array
      var file = findByPath(files.served, requestedFilePath);

      if (file) {
        serveFile(file.contentPath || file.path, response, function() {
          if (/\?\w+/.test(request.url)) {
            // files with timestamps - cache one year, rely on timestamps
            common.setHeavyCacheHeaders(response);
          } else {
            // without timestamps - no cache (debug)
            common.setNoCacheHeaders(response);
          }
        }, file.content);
      } else {
        next();
      }

      pausedRequest.resume();
    });
  };
};


// PUBLIC API
exports.create = createSourceFilesMiddleware;

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma/lib/middleware/source_files.js
hooch-0.4.1 jasmine/node_modules/karma/lib/middleware/source_files.js
hooch-0.4.0 jasmine/node_modules/karma/lib/middleware/source_files.js
hooch-0.3.0 jasmine/node_modules/karma/lib/middleware/source_files.js
hooch-0.2.1 jasmine/node_modules/karma/lib/middleware/source_files.js
hooch-0.2.0 jasmine/node_modules/karma/lib/middleware/source_files.js
hooch-0.1.0 jasmine/node_modules/karma/lib/middleware/source_files.js
hooch-0.0.8 jasmine/node_modules/karma/lib/middleware/source_files.js
hooch-0.0.7 jasmine/node_modules/karma/lib/middleware/source_files.js
hooch-0.0.6 jasmine/node_modules/karma/lib/middleware/source_files.js
entangled-0.0.16 spec/dummy/public/node_modules/karma/lib/middleware/source_files.js
entangled-0.0.15 spec/dummy/public/node_modules/karma/lib/middleware/source_files.js
entangled-0.0.14 spec/dummy/public/node_modules/karma/lib/middleware/source_files.js
entangled-0.0.13 spec/dummy/public/node_modules/karma/lib/middleware/source_files.js
entangled-0.0.12 spec/dummy/public/node_modules/karma/lib/middleware/source_files.js
entangled-0.0.11 spec/dummy/public/node_modules/karma/lib/middleware/source_files.js
entangled-0.0.10 spec/dummy/public/node_modules/karma/lib/middleware/source_files.js