Skip to content

Latest commit

 

History

History

toggle-restify

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Toggle Restify

Toggle Restify library for toggle
`toggle-restify` middleware read request headers sent and overwrite default values.

Installation

$ npm install --save @mathdoy/toggle @mathdoy/toggle-restify
import restify from "restify";
import { createToggle } from "@mathdoy/toggle";
import toggleRestifyMiddleware from "@mathdoy/toggle-restify";

const toggle = createToggle({
  prefix: "X-FEAT-",
  features: {
    food: false,
  },
});
// or use default
// const toggle = createToggle();

// You can manually send `x-feat-food: true` header to overwrite the config and test your feature

const hello = (req, res, next) => {
  const response = {
    reqToggleFeatures: req.toggle.features,
    hello: "hello handler",
    name: req.params.name,
    isFooEnabled: req.toggle.isEnabled("foo"),
    isFoodEnabled: req.toggle.isEnabled("food"),
  };

  res.send(response);
  next();
};

const server = restify.createServer();
server.use(toggleRestifyMiddleware(toggle));
server.get("/hello/:name", hello);
server.head("/hello/:name", hello);

server.listen(8080, function() {
  console.log("%s listening at %s", server.name, server.url); // eslint-disable-line no-console
});

For more information on toggle

For more information on toggle see toggle

Using it with react

$ npm install --save @mathdoy/toggle @mathdoy/toggle-react

See more information for toggle-react

License

Toggle is licensed under the MIT License.