Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/santosh1994/nextjs-ab-test-middleware
Nextjs middleware for AB test support
https://github.com/santosh1994/nextjs-ab-test-middleware
ab-testing express-middleware next-js nextjs-middleware server-side-ab
Last synced: 15 days ago
JSON representation
Nextjs middleware for AB test support
- Host: GitHub
- URL: https://github.com/santosh1994/nextjs-ab-test-middleware
- Owner: santosh1994
- License: mit
- Created: 2022-07-29T05:20:12.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-09-12T04:47:49.000Z (over 2 years ago)
- Last Synced: 2024-12-03T15:49:50.648Z (about 1 month ago)
- Topics: ab-testing, express-middleware, next-js, nextjs-middleware, server-side-ab
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AB test Middleware
[![NPM Version][npm-version-image]][npm-url]
AB test Middleware for Nextjs
## Installation
This is a [Node.js](https://nodejs.org/en/) module available through the
[npm registry](https://www.npmjs.com/). Installation is done using the
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):```sh
$ npm install nextjs-ab-test-middleware
```## API
```js
var activateAB = require("nextjs-ab-test-middleware");
```### activateAB(req, res, next, experiments)
### Sample usage
```js
var express = require("express");
const next = require("next");
var activateAB = require("nextjs-ab-test-middleware");const experiment = [
{
name: "experiment-1",
variants: [
{
id: "a",
weight: 50,
},
{
id: "b",
weight: 50,
},
],
customFilter(req, res) {
return req.originalUrl.indexOf("US") !== -1;
},
},
{
name: "experiment-2",
variants(req, res) {
if (req.originalUrl.indexOf("US") !== -1) {
return [
{
id: "a",
weight: 50,
},
{
id: "b",
weight: 50,
},
];
}
return [
{
id: "a",
weight: 100,
},
{
id: "b",
weight: 0,
},
];
},
},
];
const app = next({ dev });app
.prepare()
.then(() => {
const server = express();server.use((req, res, next) => activateAB(req, res, next, experiment));
server.use((req, res, next) => {
next();
});server.listen(3000, (err) => {
if (err) throw err;
});
})
.catch((ex) => {
console.error(ex.stack); // eslint-disable-line no-console
process.exit(1);
});
```## License
[MIT](LICENSE)
[npm-downloads-image]: https://badgen.net/npm/dm/nextjs-ab-test-middleware
[npm-url]: https://npmjs.org/package/nextjs-ab-test-middleware
[npm-version-image]: https://badgen.net/npm/v/nextjs-ab-test-middleware