Skip to content

📦 A middleware to automatically setup routes, store expected responses and deliver results fast.

License

Notifications You must be signed in to change notification settings

vaneenige/unvault-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unvault Middleware

As the name suggests this is a middleware based on unvault, a minimal layer for node that allows results of time-consuming tasks to be stored. This middleware only needs a simple configuration to automatically setup routes, store expected responses and deliver results fast (see benchmarks).

npm

Install

$ npm install --save unvault-middleware

Usage

const polka = require("polka");
const middleware = require("unvault-middleware");

const route = {
  path: "/random",
  headers: { "Content-Type": "application/json" },
  interval: 1000,
  update: () => {
    return JSON.stringify({
      random: Math.random()
    });
  }
};

polka()
  .use(middleware([route]))
  .listen(3000);

Result: The example above creates a node server (in this case with Polka) that uses the middleware. The added route (http://localhost:3000/random) will return a stored JSON (based on headers) response with a random value that is updated automatically every second.

License

MIT © Colin van Eenige.

About

📦 A middleware to automatically setup routes, store expected responses and deliver results fast.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published