mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 02:24:17 +00:00
added beforeRequest
handler
This commit is contained in:
parent
10216dd05d
commit
1c4a378fd7
@ -100,6 +100,14 @@ module.exports = class Bridge {
|
||||
return false
|
||||
}
|
||||
|
||||
handleBeforeRequest = async (request) => {
|
||||
if (typeof this.params.onBeforeRequest === "function") {
|
||||
return await this.params.onBeforeRequest(request)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
registerHTTPDispatchers = async (map) => {
|
||||
if (typeof map !== "object") {
|
||||
console.error("[Bridge] > createHTTPDispatchers > map is not an object")
|
||||
@ -136,14 +144,15 @@ module.exports = class Bridge {
|
||||
nameKey = "index"
|
||||
}
|
||||
|
||||
this.endpoints[fixedMethod][nameKey] = generateHTTPRequestDispatcher(
|
||||
this.httpInterface,
|
||||
fixedMethod,
|
||||
route,
|
||||
this.handleRequestContext,
|
||||
this.handleResponse,
|
||||
this.params.requestHeaders
|
||||
)
|
||||
this.endpoints[fixedMethod][nameKey] = generateHTTPRequestDispatcher({
|
||||
instance: this.httpInterface,
|
||||
method: fixedMethod,
|
||||
route: route,
|
||||
beforeRequest: this.handleBeforeRequest,
|
||||
handleRequestContext: this.handleRequestContext,
|
||||
handleResponse: this.handleResponse,
|
||||
requestHeaders: this.params.requestHeaders,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,11 @@
|
||||
export default function generateHTTPRequestDispatcher(instance, method, route, handleRequestContext, handleResponse) {
|
||||
export default function generateHTTPRequestDispatcher({
|
||||
instance,
|
||||
method,
|
||||
route,
|
||||
beforeRequest,
|
||||
handleRequestContext,
|
||||
handleResponse,
|
||||
}) {
|
||||
return function (body, query, options) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let requestParams = {
|
||||
@ -10,6 +17,10 @@ export default function generateHTTPRequestDispatcher(instance, method, route, h
|
||||
params: query,
|
||||
}
|
||||
|
||||
if (typeof beforeRequest === "function") {
|
||||
await beforeRequest(requestParams)
|
||||
}
|
||||
|
||||
if (typeof handleRequestContext === "function") {
|
||||
const context = await handleRequestContext()
|
||||
requestParams = { ...requestParams, ...context }
|
||||
|
Loading…
x
Reference in New Issue
Block a user