support load controllers

This commit is contained in:
srgooglo 2021-06-21 13:14:41 +02:00
parent d4586801cd
commit d80f7a3736

View File

@ -44,6 +44,7 @@ class Server {
this.routes = [] this.routes = []
this.endpoints = {} this.endpoints = {}
this.middlewares = [] this.middlewares = []
this.controllers = { ...this.params.controllers }
this.headers = { ...defaultHeaders, ...this.params.headers } this.headers = { ...defaultHeaders, ...this.params.headers }
//* set server basics //* set server basics
@ -174,8 +175,13 @@ class Server {
// check if controller is an already a controller // check if controller is an already a controller
if (typeof controller === "string") { if (typeof controller === "string") {
// check if the controller is already loaded, else try to fetch
if (typeof this.controllers[controller] !== "undefined") {
controller = this.controllers[controller]
} else {
controller = fetchController(controller) controller = fetchController(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 controller === "function") {