mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 18:44:17 +00:00
refactor endpoint registration method
This commit is contained in:
parent
09fd76e554
commit
9ecceef97d
@ -200,38 +200,36 @@ class Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let { method, route, controller, fn } = endpoint
|
|
||||||
|
|
||||||
// check if controller is an already a controller
|
// check if controller is an already a controller
|
||||||
if (typeof controller === "string") {
|
if (typeof endpoint.controller === "string") {
|
||||||
// check if the controller is already loaded, else try to fetch
|
// check if the controller is already loaded, else try to fetch
|
||||||
if (typeof this.controllers[controller] !== "undefined") {
|
if (typeof this.controllers[endpoint.controller] !== "undefined") {
|
||||||
controller = this.controllers[controller]
|
endpoint.controller = this.controllers[endpoint.controller]
|
||||||
} else {
|
} else {
|
||||||
controller = fetchController(controller)
|
endpoint.controller = fetchController(endpoint.controller)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the controller is an default function and transform it into an controller
|
// check if the controller is an default function and transform it into an controller
|
||||||
if (typeof controller === "function") {
|
if (typeof endpoint.controller === "function") {
|
||||||
controller = {
|
endpoint.controller = {
|
||||||
default: controller
|
default: endpoint.controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fullfill undefined
|
// fulfill undefined
|
||||||
if (typeof method === "undefined") {
|
if (typeof endpoint.method === "undefined") {
|
||||||
method = "GET"
|
endpoint.method = "GET"
|
||||||
}
|
}
|
||||||
if (typeof fn === "undefined") {
|
if (typeof endpoint.fn === "undefined") {
|
||||||
fn = "default"
|
endpoint.fn = "default"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convert with class
|
||||||
|
endpoint.controller = new classes.Controller(endpoint.route, endpoint.controller[endpoint.fn])
|
||||||
|
|
||||||
// append to server
|
// append to server
|
||||||
this.registerEndpoint({
|
this.registerEndpoint(endpoint)
|
||||||
...endpoint,
|
|
||||||
controller: new classes.Controller(route, controller[fn])
|
|
||||||
})
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
runtime.logger.dump(error)
|
runtime.logger.dump(error)
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user