From 996afd69b06df0db2cf6b8b5e6913a8c76b9263d Mon Sep 17 00:00:00 2001 From: srgooglo Date: Fri, 6 May 2022 13:33:25 +0200 Subject: [PATCH] use middleware for patch every request --- src/server/index.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/server/index.js b/src/server/index.js index a30b98d..c38c83e 100755 --- a/src/server/index.js +++ b/src/server/index.js @@ -116,6 +116,23 @@ class Server { } initialize = async () => { + this.httpInterface.use(async (req, res, next) => { + // make sure req has an body and query + if (typeof req.body === "undefined") { + req.body = {} + } + if (typeof req.query === "undefined") { + req.query = {} + } + + // if server has enabled urlencoded parser, parse the body + if (this.params.urlencoded) { + req.body = await req.urlencoded() + } + + next() + }) + //* set server defined headers this.initializeHeaders() @@ -312,19 +329,6 @@ class Server { throw new Error("Endpoint is disabled!") } - // make sure req has an body and query - if (typeof req.body === "undefined") { - req.body = {} - } - if (typeof req.query === "undefined") { - req.query = {} - } - - // if server has enabled urlencoded parser, parse the body - if (this.params.urlencoded) { - req.body = await req.urlencoded() - } - // return the returning call of the endpoint function return await endpoint.fn(req, res) } catch (error) {