mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 10:34:17 +00:00
move http request to method handleHTTPRequest
This commit is contained in:
parent
d0f9b7c1d6
commit
9b21671be8
@ -192,24 +192,7 @@ class Server {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
this.httpInterface[endpoint.method](endpoint.route, ...middlewares, async (req, res) => {
|
this.httpInterface[endpoint.method](endpoint.route, ...middlewares, this.handleHTTPRequest)
|
||||||
try {
|
|
||||||
// check if endpoint is disabled
|
|
||||||
if (!this.endpointsMap[endpoint.method][endpoint.route].enabled) {
|
|
||||||
throw new Error("Endpoint is disabled!")
|
|
||||||
}
|
|
||||||
|
|
||||||
return await endpoint.fn(req, res)
|
|
||||||
} catch (error) {
|
|
||||||
if (typeof this.params.onRouteError === "function") {
|
|
||||||
return this.params.onRouteError(req, res, error)
|
|
||||||
} else {
|
|
||||||
return res.status(500).json({
|
|
||||||
"error": error.message
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
registerWSEndpoint = (endpoint, ...execs) => {
|
registerWSEndpoint = (endpoint, ...execs) => {
|
||||||
@ -273,6 +256,25 @@ class Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handlers
|
// handlers
|
||||||
|
handleHTTPRequest = async (req, res) => {
|
||||||
|
try {
|
||||||
|
// check if endpoint is disabled
|
||||||
|
if (!this.endpointsMap[endpoint.method][endpoint.route].enabled) {
|
||||||
|
throw new Error("Endpoint is disabled!")
|
||||||
|
}
|
||||||
|
|
||||||
|
return await endpoint.fn(req, res)
|
||||||
|
} catch (error) {
|
||||||
|
if (typeof this.params.onRouteError === "function") {
|
||||||
|
return this.params.onRouteError(req, res, error)
|
||||||
|
} else {
|
||||||
|
return res.status(500).json({
|
||||||
|
"error": error.message
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleWSClientConnection = async (socket) => {
|
handleWSClientConnection = async (socket) => {
|
||||||
socket.res = (...args) => {
|
socket.res = (...args) => {
|
||||||
socket.emit("response", ...args)
|
socket.emit("response", ...args)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user