Comparing version 7.1.0 to 8.0.0
@@ -59,5 +59,3 @@ /** | ||
use: function (path, fn) { | ||
if (!config.get("staticFiles").has(path)) { | ||
config = config.setIn(["staticFiles", path], fn); | ||
} | ||
config = config.set("middleware", config.get("middleware").push({path: path, fn: fn})); | ||
} | ||
@@ -69,4 +67,4 @@ }; | ||
module.exports = foxy; | ||
module.exports = foxy; | ||
module.exports.init = foxy; // backwards compatibility | ||
@@ -25,3 +25,7 @@ var Immutable = require("immutable"); | ||
*/ | ||
staticFiles: {} | ||
staticFiles: {}, | ||
/** | ||
* | ||
*/ | ||
middleware: [] | ||
}); | ||
@@ -56,4 +60,16 @@ | ||
var mw = item.get("middleware"); | ||
if (typeof mw === "function") { | ||
item.set("middleware", Immutable.List([{fn: mw}])); | ||
} else { | ||
if (Immutable.List.isList(mw)) { | ||
item.set("middleware", mw.map(function (mwitem) { | ||
return {fn: mwitem}; | ||
})); | ||
} | ||
} | ||
return item; | ||
}); | ||
}; |
@@ -1,3 +0,3 @@ | ||
var respMod = require("resp-modifier"); | ||
var utils = require("./utils"); | ||
var respMod = require("resp-modifier"); | ||
var utils = require("./utils"); | ||
@@ -7,3 +7,3 @@ /** | ||
* @param proxyServer | ||
* @param config | ||
* @param userConfig | ||
* @returns {Function} | ||
@@ -36,13 +36,26 @@ */ | ||
if (config.get("staticFiles").has(req.url)) { | ||
return config.getIn(["staticFiles", req.url])(req, res); | ||
} | ||
if (config.has("middleware")) { | ||
config.get("middleware")(req, res, function (skip) { | ||
if (skip) { | ||
return; | ||
if (config.get("middleware").size) { | ||
var mw = config.get("middleware"); | ||
var size = mw.size; | ||
var count = 0; | ||
mw.forEach(function (item) { | ||
if (item.path) { | ||
if (req.url === item.path) { | ||
item.fn(req, res, function () { | ||
if (count === (size - 1)) { | ||
utils.handleIe(req); | ||
return middleware(req, res, next); | ||
} | ||
count += 1; | ||
}); | ||
} | ||
} else { | ||
item.fn(req, res, function () { | ||
if (count === (size - 1)) { | ||
utils.handleIe(req); | ||
return middleware(req, res, next); | ||
} | ||
count += 1; | ||
}); | ||
} | ||
utils.handleIe(req); | ||
middleware(req, res, next); | ||
}); | ||
@@ -49,0 +62,0 @@ } else { |
{ | ||
"name": "foxy", | ||
"version": "7.1.0", | ||
"version": "8.0.0", | ||
"description": "Proxy with response modding", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16356
475