node-ab-decider
Advanced tools
Comparing version 0.0.14 to 0.0.15
23
index.js
@@ -38,5 +38,9 @@ const proxy = require("express-http-proxy"); | ||
const resolveProxyOptions = (selectedExperiment, middlewareOptions) => { | ||
const { sendHeaderToChild = true, https = false } = middlewareOptions; | ||
const { | ||
sendHeaderToChild = true, | ||
https = false, | ||
headers = null | ||
} = middlewareOptions; | ||
const options = { | ||
const proxyOptions = { | ||
https | ||
@@ -46,3 +50,3 @@ }; | ||
if (sendHeaderToChild) { | ||
options["proxyReqOptDecorator"] = function(proxyReqOpts) { | ||
proxyOptions["proxyReqOptDecorator"] = function (proxyReqOpts) { | ||
proxyReqOpts.headers["ab-decider-child"] = "true"; | ||
@@ -52,4 +56,13 @@ return proxyReqOpts; | ||
} | ||
if (headers) { | ||
proxyOptions["userResHeaderDecorator"] = function (originHeaders) { | ||
return { | ||
...originHeaders, | ||
...headers | ||
} | ||
}; | ||
} | ||
return options; | ||
return proxyOptions; | ||
}; | ||
@@ -65,3 +78,3 @@ | ||
skip = false, | ||
hash = "nohash" | ||
hash = "nohash" | ||
} = opts; | ||
@@ -68,0 +81,0 @@ |
{ | ||
"name": "node-ab-decider", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "", | ||
@@ -11,3 +11,4 @@ "main": "index.js", | ||
"express-http-proxy": "^1.5.0", | ||
"lodash": "^4.17.11" | ||
"lodash": "^4.17.11", | ||
"nocache": "^2.0.0" | ||
}, | ||
@@ -14,0 +15,0 @@ "devDependencies": { |
@@ -74,10 +74,9 @@ ## Setup | ||
### avoidDefault | ||
if true it force to choose an option between the experiments, | ||
event if they doesn´t sum 100 | ||
### sendHeaderToChild | ||
If false it avoids to send "ab-decider-child" header to the proxied endpoint | ||
### encodeCookie | ||
Use btoa to encode the cookie value | ||
### https | ||
Force https to children | ||
### sendHeaderToChild | ||
If false it avoids to send "ab-decider-child" header to the proxied endpoint | ||
### headers | ||
Headers to include in every response |
const app = require("express")(); | ||
const { middleware: decider } = require("./index"); | ||
const port = process.env.PORT || 2323; | ||
const port = process.env.PORT || 2323; | ||
const nocache = require('nocache') | ||
@@ -18,8 +19,10 @@ const resource = () => { | ||
app.get("/test", (req, res)=>res.send("ok")) | ||
app.get("/test", (req, res) => res.send("ok")) | ||
app.use( | ||
decider(resource, {hash:123}) | ||
decider(resource, { | ||
hash: 123 | ||
}) | ||
); | ||
app.listen(port, () => console.log(`running on ${port}`)); |
20293
5
105
4
81
+ Addednocache@^2.0.0
+ Addednocache@2.1.0(transitive)