summaryrefslogtreecommitdiffstats
path: root/vnfmarket/src/main/webapp/vnfmarket/node_modules/karma/lib/middleware/source_files.js
diff options
context:
space:
mode:
Diffstat (limited to 'vnfmarket/src/main/webapp/vnfmarket/node_modules/karma/lib/middleware/source_files.js')
-rw-r--r--vnfmarket/src/main/webapp/vnfmarket/node_modules/karma/lib/middleware/source_files.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/vnfmarket/src/main/webapp/vnfmarket/node_modules/karma/lib/middleware/source_files.js b/vnfmarket/src/main/webapp/vnfmarket/node_modules/karma/lib/middleware/source_files.js
new file mode 100644
index 00000000..95d4c032
--- /dev/null
+++ b/vnfmarket/src/main/webapp/vnfmarket/node_modules/karma/lib/middleware/source_files.js
@@ -0,0 +1,59 @@
+/**
+ * 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()
+ })
+ }
+}
+
+createSourceFilesMiddleware.$inject = ['filesPromise', 'serveFile', 'config.basePath']
+
+// PUBLIC API
+exports.create = createSourceFilesMiddleware