diff --git a/src/handlers/handlerUtils.ts b/src/handlers/handlerUtils.ts index 9e3ca74d..fc1d1890 100644 --- a/src/handlers/handlerUtils.ts +++ b/src/handlers/handlerUtils.ts @@ -763,10 +763,21 @@ export async function tryTargetsRecursively( } catch (err) { metadata = {}; } + + let params = + request instanceof FormData || + request instanceof ReadableStream || + request instanceof ArrayBuffer + ? {} // Send empty object if not JSON + : request; + let conditionalRouter: ConditionalRouter; let finalTarget: Targets; try { - conditionalRouter = new ConditionalRouter(currentTarget, { metadata }); + conditionalRouter = new ConditionalRouter(currentTarget, { + metadata, + params, + }); finalTarget = conditionalRouter.resolveTarget(); } catch (conditionalRouter: any) { throw new RouterError(conditionalRouter.message); diff --git a/src/services/conditionalRouter.ts b/src/services/conditionalRouter.ts index 43553591..7bfcd55c 100644 --- a/src/services/conditionalRouter.ts +++ b/src/services/conditionalRouter.ts @@ -6,6 +6,7 @@ type Query = { interface RouterContext { metadata?: Record; + params?: Record; } enum Operator { @@ -71,13 +72,13 @@ export class ConditionalRouter { ); } - const metadataValue = this.getContextValue(key); + const contextValue = this.getContextValue(key); if (typeof value === 'object' && value !== null) { - if (!this.evaluateOperator(value, metadataValue)) { + if (!this.evaluateOperator(value, contextValue)) { return false; } - } else if (metadataValue !== value) { + } else if (contextValue !== value) { return false; } }