code: function middleware(doIt, req, res) {
    const originalEnd = res.end;
  
    return new Promise(resolve => {
      res.end = function end(...args) {
        originalEnd.apply(this, args);
        resolve(0);
      };
      doIt(req, res, () => {
        resolve(1);
      });
    });
  }
docs: const { PassThrough } = require('stream');