diff --git a/src/lib/server/broker-utils/FileSystem/Endpoint-Manager.ts b/src/lib/server/broker-utils/FileSystem/Endpoint-Manager.ts index 4fa936e..576cedd 100644 --- a/src/lib/server/broker-utils/FileSystem/Endpoint-Manager.ts +++ b/src/lib/server/broker-utils/FileSystem/Endpoint-Manager.ts @@ -24,23 +24,28 @@ export class EndpointBrokerManagerFS { } public static async init() { - + if (EndpointBrokerManagerFS.ready) { // UGLY: be specific throw new Error("Broker already initialized") } - - const configurations = (await listFiles(NGINX_TRACKED, true)).filter( async (path) => { - if (await isDir(path)) { - return false + + const candidateConfigurations = (await listFiles(NGINX_TRACKED, true)) + const configurations: string[] = [] + + for (const candidatePath of candidateConfigurations) { + if (await isDir(candidatePath)) { + continue } - if (!path.endsWith(".conf")) { - return false + if (!candidatePath.endsWith(".conf")) { + continue } - return true - }) + configurations.push(candidatePath) + } + + for (const confPath of configurations) { const file = await loadFile(confPath) @@ -66,7 +71,7 @@ export class EndpointBrokerManagerFS { ) } - + // TODO: Initialize a file watcher EndpointBrokerManagerFS.watcher = EndpointBrokerManagerFS.watchNginxDirectory() @@ -81,7 +86,7 @@ export class EndpointBrokerManagerFS { const REAL_PATH = `${NGINX_TRACKED}/${endpoint.path}` - if (await doesFileExist(REAL_PATH) ) { + if (await doesFileExist(REAL_PATH)) { // UGLY: be specific throw new Error("File already existant") } @@ -263,7 +268,7 @@ export class EndpointBrokerManagerFS { // UGLY: more specific throw new Error("This path is non existant") - + }