Skip to content

Commit

Permalink
fix: this.modules
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed Nov 28, 2023
1 parent bc219f0 commit 7839c7f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ class CoCreateLazyLoader {
// TODO: return the value so it can be applied directly to modules
// this.modules[key] = await Config('modules', false, false)

const config = await Config('modules', false, false)
if (!config)
this.modules = await Config('modules', false, false)
if (!this.modules)
return
else
this.modules = this.modules.modules

for (let name of Object.keys(config.modules)) {
this.modules[name] = config.modules[name];
for (let name of Object.keys(this.modules)) {
this.wsManager.on(this.modules[name].event, async (data) => {
this.executeScriptWithTimeout(name, data)
});
Expand Down Expand Up @@ -73,14 +74,15 @@ class CoCreateLazyLoader {
} else {
organization = org.object[0]
organizations[organization._id] = organization
hosts[hostname] = organization
}
}

hosts[hostname] = organization

if (valideUrl.pathname.startsWith('/webhooks/')) {
let name = req.url.split('/')[2]; // Assuming URL structure is /webhook/name/...
if (this.modules[name]) {
this.executeScriptWithTimeout(name, { req, res, crud: this.crud, organization, valideUrl })
this.executeScriptWithTimeout(name, { req, res, crud: this.crud, organization, valideUrl, organization_id: data.organization })
} else {
// Handle unknown module or missing webhook method
res.writeHead(404, { 'Content-Type': 'application/json' });
Expand Down

0 comments on commit 7839c7f

Please sign in to comment.