support urlencoded

This commit is contained in:
srgooglo 2022-05-06 12:05:10 +02:00
parent a815c07a2d
commit 9a5296661f

View File

@ -294,6 +294,20 @@ class Server {
throw new Error("Endpoint is disabled!") 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) return await endpoint.fn(req, res)
} catch (error) { } catch (error) {
if (typeof this.params.onRouteError === "function") { if (typeof this.params.onRouteError === "function") {