summaryrefslogtreecommitdiff
path: root/src/node/hooks
diff options
context:
space:
mode:
authorJohn McLear <john@mclear.co.uk>2012-09-03 14:56:55 -0700
committerJohn McLear <john@mclear.co.uk>2012-09-03 14:56:55 -0700
commitc5be2eb418c9d3c589c489efa933152b45953b6b (patch)
treebfd6beeac5a726a3123c535e0a365a75d200f53f /src/node/hooks
parentde7934d9fbfdc385ab1b8e4c9654b90c69207d03 (diff)
parent6e796eb5fbaf7c842ecdecabd48f8065eaec1084 (diff)
downloadetherpad-lite-c5be2eb418c9d3c589c489efa933152b45953b6b.zip
Merge pull request #977 from cweider/loopback-avoidance
Loopback avoidance
Diffstat (limited to 'src/node/hooks')
-rw-r--r--src/node/hooks/express/static.js68
1 files changed, 1 insertions, 67 deletions
diff --git a/src/node/hooks/express/static.js b/src/node/hooks/express/static.js
index 0d78da2f..7d654c1b 100644
--- a/src/node/hooks/express/static.js
+++ b/src/node/hooks/express/static.js
@@ -7,74 +7,8 @@ var Yajsml = require('yajsml');
var fs = require("fs");
var ERR = require("async-stacktrace");
var _ = require("underscore");
-var urlutil = require('url');
exports.expressCreateServer = function (hook_name, args, cb) {
- // 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.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);
- };
- }
-
-
// Cache both minified and static.
var assetCache = new CachingMiddleware;
@@ -91,7 +25,7 @@ exports.expressCreateServer = function (hook_name, args, cb) {
, rootURI: 'http://localhost:' + settings.port + '/static/js/'
, libraryPath: 'javascripts/lib/'
, libraryURI: 'http://localhost:' + settings.port + '/static/plugins/'
- , requestURIs: requestURIs // Loop-back is causing problems, this is a workaround.
+ , requestURIs: minify.requestURIs // Loop-back is causing problems, this is a workaround.
});
var StaticAssociator = Yajsml.associators.StaticAssociator;