* Return a request handler callback * for node's native http server. * * @return {Function} * @api public
()
| 165 | */ |
| 166 | |
| 167 | callback () { |
| 168 | const fn = this.compose(this.middleware) |
| 169 | |
| 170 | if (!this.listenerCount(class="st">'error')) this.on(class="st">'error', this.onerror) |
| 171 | |
| 172 | const handleRequest = (req, res) => { |
| 173 | const ctx = this.createContext(req, res) |
| 174 | if (!this.ctxStorage) { |
| 175 | return this.handleRequest(ctx, fn) |
| 176 | } |
| 177 | return this.ctxStorage.run(ctx, async () => { |
| 178 | return await this.handleRequest(ctx, fn) |
| 179 | }) |
| 180 | } |
| 181 | |
| 182 | return handleRequest |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * return current context from async local storage |
no outgoing calls