MCPcopy
hub / github.com/socketio/socket.io / _applyMiddlewares

Function _applyMiddlewares

packages/engine.io/lib/server.ts:372–398  ·  view source on GitHub ↗

* Apply the middlewares to the request. * * @param req * @param res * @param callback * @protected

(
    req: IncomingMessage,
    res: ServerResponse,
    callback: (err?: any) => void,
  )

Source from the content-addressed store, hash-verified

370 * @protected
371 */
372 protected _applyMiddlewares(
373 req: IncomingMessage,
374 res: ServerResponse,
375 callback: (err?: any) => void,
376 ) {
377 if (this.middlewares.length === 0) {
378 debug("no middleware to apply, skipping");
379 return callback();
380 }
381
382 const apply = (i) => {
383 debug("applying middleware n°%d", i + 1);
384 this.middlewares[i](req, res, (err?: any) => {
385 if (err) {
386 return callback(err);
387 }
388
389 if (i + 1 < this.middlewares.length) {
390 apply(i + 1);
391 } else {
392 callback();
393 }
394 });
395 };
396
397 apply(0);
398 }
399
400 /**
401 * Closes all clients.

Callers

nothing calls this directly

Calls 3

debugFunction · 0.85
applyFunction · 0.85
callbackFunction · 0.50

Tested by

no test coverage detected