allow load controller from

This commit is contained in:
srgooglo 2021-07-20 14:49:52 +02:00
parent 0ee8455ae9
commit fdd221f8a7
6 changed files with 3 additions and 15 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -1,5 +0,0 @@
class Authorization {
}
module.exports = { Authorization }

View File

@ -1,5 +0,0 @@
class Database {
}
module.exports = { Database }

View File

@ -1,4 +1,2 @@
export { Authorization } from './Authorization'
export { Controller } from './Controller' export { Controller } from './Controller'
export { Database } from './Database'
export { Storage } from './Storage' export { Storage } from './Storage'

View File

@ -1,9 +1,9 @@
const fs = require("fs") const fs = require("fs")
const path = require("path") const path = require("path")
function fetchController(key) { function fetchController(key, from) {
try { try {
const controllersPath = global.controllersPath ?? path.resolve(process.cwd(), `controllers`) const controllersPath = from ?? path.resolve(process.cwd(), `controllers`)
const controllerPath = path.join(controllersPath, key) const controllerPath = path.join(controllersPath, key)
if (fs.existsSync(controllerPath)) { if (fs.existsSync(controllerPath)) {

View File

@ -213,7 +213,7 @@ class Server {
if (typeof this.controllers[endpoint.controller] !== "undefined") { if (typeof this.controllers[endpoint.controller] !== "undefined") {
endpoint.controller = this.controllers[endpoint.controller] endpoint.controller = this.controllers[endpoint.controller]
} else { } else {
endpoint.controller = fetchController(endpoint.controller) endpoint.controller = fetchController(endpoint.controller, this.params.controllersPath)
} }
} }