ab-test-middleware
Advanced tools
Comparing version 0.1.5-alpha to 0.1.6-alpha
@@ -7,3 +7,3 @@ const path = require('path'); | ||
const { | ||
distFolder, defaultDist, distPath, entryFile, ingresses | ||
distFolder, defaultDist, distPath, entryFile, ingresses, modifiedBaseUrl | ||
} = req.locals; | ||
@@ -13,3 +13,3 @@ if (!req.baseUrl || ingresses.includes(req.baseUrl)) { | ||
} | ||
return res.sendFile(path.join(defaultDist, req.baseUrl), { root: distPath, index: false }); | ||
return res.sendFile(path.join(defaultDist, modifiedBaseUrl), { root: distPath, index: false }); | ||
} catch (e) { | ||
@@ -16,0 +16,0 @@ return next(e); |
@@ -8,2 +8,10 @@ /* eslint-disable no-param-reassign */ | ||
const preprocessBaseUrl = (req) => { | ||
if (!req.baseUrl) return; | ||
let modifiedBaseUrl = req.baseUrl; | ||
ingresses.map((i) => RegExp(`^${i}`)) | ||
.forEach((regExp) => modifiedBaseUrl = modifiedBaseUrl.replace(regExp, '')) | ||
return modifiedBaseUrl; | ||
} | ||
const distributionMiddleware = (req, res, next) => { | ||
@@ -16,2 +24,3 @@ try { | ||
req.locals.ingresses = ingresses; | ||
req.locals.modifiedBaseUrl = preprocessBaseUrl(req); | ||
const filteredPaths = dists.filter((d) => d === dist && distributionToggles[d]); | ||
@@ -22,3 +31,4 @@ if (filteredPaths.length === 1) { | ||
} | ||
return res.sendFile(path.join(dist, req.baseUrl), { root: distPath, index: false }); | ||
return res.sendFile(path.join(dist, req.locals.modifiedBaseUrl), { root: distPath, index: false }); | ||
} | ||
@@ -25,0 +35,0 @@ } catch (e) { |
{ | ||
"name": "ab-test-middleware", | ||
"version": "0.1.5-alpha", | ||
"version": "0.1.6-alpha", | ||
"description": "An express middleware that manages multiple distributions for A/B/N testing purposes.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,5 +6,8 @@ # ab-test-middleware | ||
## TL;DR | ||
## Usage (the TL;DR version) | ||
Assuming your distributions are built already and available in your `build` folder with the following structure: | ||
Assuming your distributions are built already and available in your `build` folder. | ||
I suggest using [navikt/ab-test/actions/build@v1](https://github.com/navikt/ab-test/tree/main/actions/build) | ||
if you're running your deployments by means of GitHub Actions. | ||
The `build` folder should be created with the following structure: | ||
``` | ||
@@ -11,0 +14,0 @@ build/ |
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
14754
283
74