Skip to content

Instantly share code, notes, and snippets.

@ORESoftware
Created December 27, 2022 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ORESoftware/629ef6c6f3dd97374d1e8597f89c9c9e to your computer and use it in GitHub Desktop.
Save ORESoftware/629ef6c6f3dd97374d1e8597f89c9c9e to your computer and use it in GitHub Desktop.

we can use this domain middleware

const Domain = require('domain');

app.use((req,res,next) => {

  const d = Domain.create();
  
  d.once('error', e => {
  
      if(!res.headersSent){
        // clean up response
      }
  });
  
  d.run(next);

});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment