feature-render
v0.0.3
Published
middleware to feature toggle alternative views
Downloads
3
Readme
node-feature-render
Description
feature-render is Express middleware that allows you to switch rendered views by passing a feature toggle in a query string.
Installation
$ npm install feature-render
Usage
feature-render is standard Express middleware and is enabled as follows:
var express = require('express'),
featureRender = require('../index'),
app = express();
app.engine('ejs', require('ejs').renderFile);
app.use(featureRender);
Feature toggles are used by passing in a query parameter called "ft" to the query string of a url. For example to pass a feature toggle called 'newfeature', your url should be something like http://mydomain.com/path?ft=newfeature.
Once enabled any call to render on your response will look for an alternative view with the naming convention -.. For example if you have enabled a feature toggle called newfeature and you call res.render('myview.ejs') then if a view called myview-newfeature.ejs exists then that view will be rendered instead. If no view is found or no feature toggle is passed the original view is rendered (in this case "myview.ejs").
In the example, if you browse to http://localhost:8000, then the default view called index.ejs will be rendered.
Passing in a feature toggle called toggle1 in the query string will result in index-toggle1.ejs being rendered.
If you pass in the toggle2 feature toggle by browsing to http://localhost:8000?ft=toggle2, index.ejs will be rendered as there is no overloaded view for toggle2.