Fixed a bug where the map wasn't initialized before use

This commit is contained in:
Christian Risi 2025-07-04 10:11:57 +00:00
parent 15f38a3f62
commit 37d977e444

View File

@ -30,6 +30,8 @@ export class EndpointBrokerManagerFS {
throw new Error("Broker already initialized")
}
EndpointBrokerManagerFS.endpoints = new Map()
const candidateConfigurations = (await listFiles(NGINX_TRACKED, true))
const configurations: string[] = []
@ -64,6 +66,11 @@ export class EndpointBrokerManagerFS {
await file.release()
const endpoint = await parseConf(fsHeader, conf)
logger.debug(
`Parsed Conf:\n${endpoint}`,
"Manager Init"
)
const relativePath = confPath.replace(NGINX_TRACKED, "")
EndpointBrokerManagerFS.endpoints.set(
relativePath,
@ -291,13 +298,24 @@ export class EndpointBrokerManagerFS {
const WATCHER = watch(NGINX_TRACK, OPTIONS, async (eventType, filename) => {
logger.debug(
`EVENT: ${eventType}\nFile: ${filename}`,
"Watcher "
)
if (!filename) {
return
}
const RELATIVE_PATH = filename
const FULL_PATH = `${NGINX_TRACK}/${RELATIVE_PATH}`
if (!RELATIVE_PATH.endsWith(".conf")) {
return
}
// TODO: check if it's a directory, if so, skip
@ -420,6 +438,11 @@ export class EndpointBrokerManagerFS {
}
const endpoint = parseConf(fsHeader, conf)
logger.debug(
`Endpoint:\n${endpoint}`,
"Watcher Parsing"
)
EndpointBrokerManagerFS.endpoints.set(
RELATIVE_PATH,
endpoint