(
route: WebSocketRoute | BrowserWebsocketRoute,
)
| 320 | } |
| 321 | |
| 322 | public registerWebSocketRoute( |
| 323 | route: WebSocketRoute | BrowserWebsocketRoute, |
| 324 | ): WebSocketRoute | BrowserWebsocketRoute { |
| 325 | this.log.trace(`Registering WebSocket "${route.path}"`); |
| 326 | |
| 327 | const bound = route.handler.bind(route); |
| 328 | const wrapped = this.wrapWebSocketHandler(route, bound); |
| 329 | |
| 330 | // Invariant: exactly one of limiter.limit / wrapWithAfterHook wraps the |
| 331 | // handler, so hooks.after() fires exactly once per request. |
| 332 | route.handler = route.concurrency |
| 333 | ? this.limiter.limit( |
| 334 | wrapped, |
| 335 | this.onQueueFullWebSocket.bind(this), |
| 336 | this.onWebsocketTimeout.bind(this), |
| 337 | this.getTimeout.bind(this), |
| 338 | route.bypassLimits?.bind(route), |
| 339 | route, |
| 340 | ) |
| 341 | : this.wrapWithAfterHook(wrapped, route); |
| 342 | route.path = Array.isArray(route.path) ? route.path : [route.path]; |
| 343 | this.compilePathMatchers(route); |
| 344 | const registeredPaths = this.webSocketRoutes.map((r) => r.path).flat(); |
| 345 | const duplicatePaths = registeredPaths.filter((path) => |
| 346 | route.path.includes(path), |
| 347 | ); |
| 348 | |
| 349 | if (duplicatePaths.length) { |
| 350 | this.log.warn(`Found duplicate routes: ${duplicatePaths.join(', ')}`); |
| 351 | } |
| 352 | this.webSocketRoutes.push(route); |
| 353 | return route; |
| 354 | } |
| 355 | |
| 356 | public getStaticHandler() { |
| 357 | return this.httpRoutes.find((route) => |
no test coverage detected