mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 02:24:17 +00:00
use middleware for patch every request
This commit is contained in:
parent
b4da6b3db9
commit
996afd69b0
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user