From b5c38969b34cc7fe95164adc9b0db5ffbce60c06 Mon Sep 17 00:00:00 2001 From: Vladyslav Tkachenko Date: Fri, 11 Aug 2023 16:45:35 +0300 Subject: [PATCH] feat: add path parameter to the request handlers --- src/Prxi.ts | 6 +++--- src/interfaces/RequestHandler.ts | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Prxi.ts b/src/Prxi.ts index 2d3b826..a62022e 100644 --- a/src/Prxi.ts +++ b/src/Prxi.ts @@ -98,7 +98,7 @@ export class Prxi { ): Promise => { this.logInfo(`[${requestId}] [Prxi] Handling HTTP proxy request for path: ${path}`); await proxy.http.proxy(requestId, req, res, proxyConfiguration); - }).catch((err) => { + }, path).catch((err) => { this.logError(`[${requestId}] [Prxi] Error occurred upon making the "${req.method}:${path}" request`, err); errorHandler(req, res, err).catch(err => { this.logError(`[${requestId}] [Prxi] Unable to handle error with errorHandler`, err); @@ -133,7 +133,7 @@ export class Prxi { handler.handle(req, socket, head, async (proxyConfiguration?: ProxyRequestConfiguration): Promise => { this.logInfo(`[${requestId}] [Prxi] Handling WS proxy request for path: ${path}`); await proxy.ws.proxy(requestId, req, socket, head, proxyConfiguration); - }) + }, path) .catch(err => { this.logError(`[${requestId}] [Prxi] Unable to handle websocket request`, err); @@ -251,7 +251,7 @@ export class Prxi { res(); }); }); - } else {Prxi + } else { this.logInfo('Prxi stopping skipped, not running'); } diff --git a/src/interfaces/RequestHandler.ts b/src/interfaces/RequestHandler.ts index 1cf50b7..1bdf7fa 100644 --- a/src/interfaces/RequestHandler.ts +++ b/src/interfaces/RequestHandler.ts @@ -10,6 +10,7 @@ export type HandleFunction = ( req: IncomingMessage, res: ServerResponse, proxyRequest: ProxyRequest, + path: string ) => Promise; export type WebSocketHandlerFunction = ( @@ -17,6 +18,7 @@ export type WebSocketHandlerFunction = ( socket: Socket, head: Buffer, proxyRequest: ProxyRequest, + path: string ) => Promise; export interface WebSocketHandlerConfig {