mirror of
https://github.com/abrendan/MicDropMessages.git
synced 2025-08-27 15:02:03 +02:00
Initial commit
This commit is contained in:
22
node_modules/server/src/modern/index.js
generated
vendored
Normal file
22
node_modules/server/src/modern/index.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
// Modern - Create a modern middleware from the old-style one
|
||||
|
||||
// Cleanly validate data
|
||||
const validate = require('./validate');
|
||||
|
||||
// Pass it an old middleware and return a new one 'ctx => promise'
|
||||
module.exports = middle => {
|
||||
|
||||
// Validate it early so no requests need to be made
|
||||
validate.middleware(middle);
|
||||
|
||||
// Create and return the modern middleware function
|
||||
return ctx => new Promise((resolve, reject) => {
|
||||
validate.context(ctx);
|
||||
|
||||
// It can handle both success or errors. Pass the right ctx
|
||||
const next = err => err ? reject(err) : resolve();
|
||||
|
||||
// Call the old middleware
|
||||
middle(ctx.req, ctx.res, next);
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user