From 9a5296661f218e8bd2d676bf11c413c950f5ea5a Mon Sep 17 00:00:00 2001 From: srgooglo Date: Fri, 6 May 2022 12:05:10 +0200 Subject: [PATCH] support `urlencoded` --- src/server/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/server/index.js b/src/server/index.js index c3f91e8..8c1e85e 100755 --- a/src/server/index.js +++ b/src/server/index.js @@ -294,6 +294,20 @@ 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) { if (typeof this.params.onRouteError === "function") {