mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 10:34:17 +00:00
added support for endpoint function transformation
This commit is contained in:
parent
28a99afae4
commit
132d3fd009
@ -43,7 +43,7 @@ module.exports = class Controller {
|
||||
const methodEndpoints = Object.entries(endpointsByMethod)
|
||||
|
||||
for (let [endpointKey, endpoint] of methodEndpoints) {
|
||||
// check if endpoint is a class or an object, if it's a object, create a new class from it extending Endpoint
|
||||
// Handle endpoint transformation as an object
|
||||
if (typeof endpoint === "object") {
|
||||
const objEndpoint = endpoint
|
||||
|
||||
@ -62,6 +62,21 @@ module.exports = class Controller {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle endpoint transformation as a function
|
||||
if (typeof endpoint === "function") {
|
||||
const endpointFn = endpoint
|
||||
|
||||
endpoint = class extends Endpoint {
|
||||
static method = httpMethodKey
|
||||
static route = endpointKey
|
||||
|
||||
constructor(args) {
|
||||
super(args)
|
||||
this.fn = endpointFn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check if endpoint is a class
|
||||
if (typeof endpoint !== "function") {
|
||||
throw new Error(`Invalid endpoint. Expected class or object, got ${typeof endpoint}`)
|
||||
|
Loading…
x
Reference in New Issue
Block a user