| 40 | // It has significant negative performance impact |
| 41 | // Warning: this feature depends on the deprecated domains module |
| 42 | function handleWithDomain(req, res, onError, next) { |
| 43 | // In Node v12.x requiring the domain module has a negative performance |
| 44 | // impact. As using domains in restify is optional and only required |
| 45 | // with the `handleUncaughtExceptions` options, we apply a singleton |
| 46 | // pattern to avoid any performance regression in the default scenario. |
| 47 | if (!domain) { |
| 48 | domain = require('domain'); |
| 49 | } |
| 50 | |
| 51 | var handlerDomain = domain.create(); |
| 52 | handlerDomain.add(req); |
| 53 | handlerDomain.add(res); |
| 54 | handlerDomain.on('error', onError); |
| 55 | handlerDomain.run(function run() { |
| 56 | next(req, res); |
| 57 | }); |
| 58 | } |
| 59 | |
| 60 | ///--- API |
| 61 | |