From 429d3fac74b2e0027723805ddfd9221273f2114c Mon Sep 17 00:00:00 2001 From: Lawrence Ephrim Date: Sun, 28 Jul 2024 20:34:16 +0000 Subject: [PATCH] fix(express): json content reading error --- src/core/app.core.ts | 2 +- src/core/request_handler.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/app.core.ts b/src/core/app.core.ts index 23ea647..73cc0e1 100644 --- a/src/core/app.core.ts +++ b/src/core/app.core.ts @@ -68,7 +68,7 @@ export class Ananse { const data = req.body; try { - if (req.headers["content-type"] === "application/json") { + if (req.headers["content-type"] != null && req.headers["content-type"]?.indexOf("application/json") > -1) { request.body = data; } // TODO: parse other content types diff --git a/src/core/request_handler.ts b/src/core/request_handler.ts index 9c7334d..5b07c02 100644 --- a/src/core/request_handler.ts +++ b/src/core/request_handler.ts @@ -398,7 +398,7 @@ export class RequestHandler { } private async resolveGateway(stage: "request" | "response") { - if (stage == "request") { + if (stage === "request") { const item = new this.config.gateway(this.request, this.response); const _state = (await item.handleRequest(this.request, this.response))!; await this.session.setState(_state.sessionId, _state)!; @@ -406,7 +406,7 @@ export class RequestHandler { return _state; } - if (stage == "response") { + if (stage === "response") { const item = new this.config.gateway(this.request, this.response); await item.handleResponse(this.request, this.response); }