diff options
author | Chad Weider <cweider@oofn.net> | 2012-09-03 14:37:10 -0700 |
---|---|---|
committer | Chad Weider <cweider@oofn.net> | 2012-09-03 14:37:26 -0700 |
commit | 024a26f2729890a1e7a2966dea74cd69a6cf1d59 (patch) | |
tree | 6bea76e848a2c91e7c296c6e65d919d194eb8bc3 /src/node/utils | |
parent | 4413d498d890c49192fc8b539a8b77f6e2141820 (diff) | |
download | etherpad-lite-024a26f2729890a1e7a2966dea74cd69a6cf1d59.zip |
Minify publishes its own mock request thing.
Diffstat (limited to 'src/node/utils')
-rw-r--r-- | src/node/utils/Minify.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/node/utils/Minify.js b/src/node/utils/Minify.js index 731f2f83..e8b73606 100644 --- a/src/node/utils/Minify.js +++ b/src/node/utils/Minify.js @@ -29,6 +29,7 @@ var pro = require("uglify-js").uglify; var path = require('path'); var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins"); var RequireKernel = require('require-kernel'); +var urlutil = require('url'); var ROOT_DIR = path.normalize(__dirname + "/../../static/"); var TAR_PATH = path.join(__dirname, 'tar.json'); @@ -46,6 +47,70 @@ for (var key in tar) { ); } +// What follows is a terrible hack to avoid loop-back within the server. +// TODO: Serve files from another service, or directly from the file system. +function requestURI(url, method, headers, callback, redirectCount) { + var parsedURL = urlutil.parse(url); + + var status = 500, headers = {}, content = []; + + var mockRequest = { + url: url + , method: method + , params: {filename: parsedURL.path.replace(/^\/static\//, '')} + , headers: headers + }; + var mockResponse = { + writeHead: function (_status, _headers) { + status = _status; + for (var header in _headers) { + if (Object.prototype.hasOwnProperty.call(_headers, header)) { + headers[header] = _headers[header]; + } + } + } + , setHeader: function (header, value) { + headers[header.toLowerCase()] = value.toString(); + } + , header: function (header, value) { + headers[header.toLowerCase()] = value.toString(); + } + , write: function (_content) { + _content && content.push(_content); + } + , end: function (_content) { + _content && content.push(_content); + callback(status, headers, content.join('')); + } + }; + + minify(mockRequest, mockResponse); +} +function requestURIs(locations, method, headers, callback) { + var pendingRequests = locations.length; + var responses = []; + + function respondFor(i) { + return function (status, headers, content) { + responses[i] = [status, headers, content]; + if (--pendingRequests == 0) { + completed(); + } + }; + } + + for (var i = 0, ii = locations.length; i < ii; i++) { + requestURI(locations[i], method, headers, respondFor(i)); + } + + function completed() { + var statuss = responses.map(function (x) {return x[0]}); + var headerss = responses.map(function (x) {return x[1]}); + var contentss = responses.map(function (x) {return x[2]}); + callback(statuss, headerss, contentss); + }; +} + /** * creates the minifed javascript for the given minified name * @param req the Express request @@ -321,3 +386,6 @@ function compressCSS(values) } exports.minify = minify; + +exports.requestURI = requestURI; +exports.requestURIs = requestURIs; |