Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c46b449

Browse files
feat: handle nested initailization function
1 parent 20c47b6 commit c46b449

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

‎src/server.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,22 @@ class CoCreateLazyLoader {
193193
throw new Error(`Missing ${name} key in organization apis object`);
194194

195195
// ToDo: if data.endpoint service not required as endpoint will be used
196-
const service = require(config.path);
197-
let instance
198-
if (config.initialize)
199-
instance = new service[config.initialize](key);
200-
else
201-
instance = new service(key);
196+
let instance = require(config.path);
197+
198+
if (config.initialize) {
199+
const initialize = config.initialize.split('.');
200+
201+
// Traverse the nested structure to reach the correct constructor
202+
for (let i = 0; i < initialize.length; i++) {
203+
if (instance[initialize[i]]) {
204+
instance = instance[initialize[i]];
205+
} else {
206+
throw new Error(`Service path ${config.initialize} is incorrect at ${initialize[i]}`);
207+
}
208+
}
209+
}
210+
211+
instance = new instance(key);
202212

203213
let params = [], mainParam = false
204214
for (let i = 0; true; i++) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /