Skip to content

Commit 0e6ecba

Browse files
committed
Ensure the startup is completed before calling startupCompleted
1 parent d35eeb8 commit 0e6ecba

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/ParseServer.js

+19-17
Original file line numberDiff line numberDiff line change
@@ -82,38 +82,40 @@ class ParseServer {
8282

8383
logging.setLogger(loggerController);
8484

85+
if (cloud) {
86+
addParseCloud();
87+
if (typeof cloud === 'function') {
88+
cloud(Parse);
89+
} else if (typeof cloud === 'string') {
90+
require(path.resolve(process.cwd(), cloud));
91+
} else {
92+
throw "argument 'cloud' must either be a string or a function";
93+
}
94+
}
95+
8596
// Note: Tests will start to fail if any validation happens after this is called.
86-
databaseController
87-
.performInitialization()
88-
.then(() => hooksController.load())
97+
Promise.resolve()
98+
.then(async () => await databaseController.performInitialization())
99+
.then(async () => await hooksController.load())
89100
.then(async () => {
90101
if (schema) {
91102
await new DefinedSchemas(schema, this.config).execute();
92103
}
104+
})
105+
.then(async () => {
93106
if (serverStartComplete) {
94-
serverStartComplete();
107+
await serverStartComplete();
95108
}
96109
})
97-
.catch(error => {
110+
.catch(async (error) => {
98111
if (serverStartComplete) {
99-
serverStartComplete(error);
112+
await serverStartComplete(error);
100113
} else {
101114
console.error(error);
102115
process.exit(1);
103116
}
104117
});
105118

106-
if (cloud) {
107-
addParseCloud();
108-
if (typeof cloud === 'function') {
109-
cloud(Parse);
110-
} else if (typeof cloud === 'string') {
111-
require(path.resolve(process.cwd(), cloud));
112-
} else {
113-
throw "argument 'cloud' must either be a string or a function";
114-
}
115-
}
116-
117119
if (security && security.enableCheck && security.enableCheckLog) {
118120
new CheckRunner(options.security).run();
119121
}

0 commit comments

Comments
 (0)