Socket
Socket
Sign inDemoInstall

middl

Package Overview
Dependencies
6
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.1 to 0.2.2

2

package.json
{
"name": "middl",
"version": "0.2.1",
"version": "0.2.2",
"description": "A generic middleware library, inspired by Express and suitable for anything",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -50,3 +50,3 @@ # middl

// a time measuring logger:
app.use((input, output) => {
app.use((input, output, next) => {
var start = new Date();

@@ -60,3 +60,3 @@ next()

// or even prettier with generator functions:
app.use(function *(input, output) {
app.use(function *(input, output, next) {
var start = new Date();

@@ -68,3 +68,3 @@ yield next();

// or when using Babel and async/await:
app.use(async (input, output) => {
app.use(async (input, output, next) => {
var start = new Date();

@@ -76,2 +76,23 @@ await next();

// an error handling middleware
app.use((err, input, output, next) => {
if (err) {
console.error(err);
// by not calling next() we abort the chain
} else {
next();
}
});
// conditional middleware
// this will be run because the conditions ({val: 'hello'}) matches the input:
app.match({val: 'hello'}, (input, output) => {
output.response = 'world';
});
// this won't run because the conditions ({val: 'hi'}) does not match the input
app.match({val: 'hi'}, (input, output) => {
output.response = 'there';
});
// pass in the initial `input` and `output` objects

@@ -82,2 +103,3 @@ // and run the middleware stack:

// output.prop === 2
// output.response = 'world'
});

@@ -84,0 +106,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc