@expressots/adapter-express 3.0.0-beta.4 → 3.0.0-beta.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -218,15 +218,28 @@ class AppExpress {
|
|
|
218
218
|
await this.configEngine();
|
|
219
219
|
this.environment = this.environment || "development";
|
|
220
220
|
this.app.set("env", this.environment);
|
|
221
|
-
this.port = typeof port === "string" ? parseInt(port, 10) : port
|
|
222
|
-
|
|
223
|
-
this.
|
|
224
|
-
|
|
225
|
-
|
|
221
|
+
this.port = typeof port === "string" ? parseInt(port, 10) : port;
|
|
222
|
+
return new Promise((resolve, reject) => {
|
|
223
|
+
this.serverInstance = this.app.listen(this.port, async () => {
|
|
224
|
+
this.port = this.serverInstance?.address()?.port;
|
|
225
|
+
this.console.messageServer(this.port, this.environment, appInfo);
|
|
226
|
+
["SIGTERM", "SIGHUP", "SIGBREAK", "SIGQUIT", "SIGINT"].forEach((signal) => {
|
|
227
|
+
process_1.default.on(signal, this.handleExit.bind(this));
|
|
228
|
+
});
|
|
229
|
+
try {
|
|
230
|
+
await this.postServerInitialization();
|
|
231
|
+
resolve(this);
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
this.logger.error(`Error during post-server initialization: ${error}`, "adapter-express");
|
|
235
|
+
reject(error);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
this.serverInstance?.on("error", (error) => {
|
|
239
|
+
this.logger.error(`Error starting server: ${error.message}`, "adapter-express");
|
|
240
|
+
reject(error);
|
|
226
241
|
});
|
|
227
242
|
});
|
|
228
|
-
await this.postServerInitialization();
|
|
229
|
-
return this;
|
|
230
243
|
}
|
|
231
244
|
/**
|
|
232
245
|
* Sets the global route prefix for the application.
|
|
@@ -146,14 +146,21 @@ class AppExpressMicro {
|
|
|
146
146
|
*/
|
|
147
147
|
async listen(port, appInfo) {
|
|
148
148
|
const logger = new core_1.Logger();
|
|
149
|
-
|
|
149
|
+
const normalizedPort = typeof port === "string" ? parseInt(port, 10) : port;
|
|
150
150
|
this.configureMiddleware();
|
|
151
151
|
this.routeManager.applyRoutes();
|
|
152
152
|
if (this.Middleware.getErrorHandler()) {
|
|
153
153
|
this.app.use(this.Middleware.getErrorHandler());
|
|
154
154
|
}
|
|
155
|
-
return new Promise((resolve) => {
|
|
156
|
-
this.app.listen(
|
|
155
|
+
return new Promise((resolve, reject) => {
|
|
156
|
+
const server = this.app.listen(normalizedPort, () => {
|
|
157
|
+
const address = server.address();
|
|
158
|
+
if (typeof address === "object" && address?.port) {
|
|
159
|
+
this.port = address.port;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
this.port = normalizedPort;
|
|
163
|
+
}
|
|
157
164
|
const appInfoNormalized = appInfo ? `${appInfo?.appName} - ${appInfo?.appVersion} ` : "";
|
|
158
165
|
logger.info(`${appInfoNormalized}[${this.port}:${this.environment}]`, "MicroAPI");
|
|
159
166
|
["SIGTERM", "SIGHUP", "SIGBREAK", "SIGQUIT", "SIGINT"].forEach((signal) => {
|
|
@@ -161,6 +168,10 @@ class AppExpressMicro {
|
|
|
161
168
|
});
|
|
162
169
|
resolve();
|
|
163
170
|
});
|
|
171
|
+
server.on("error", (error) => {
|
|
172
|
+
logger.error(`Error starting server: ${error.message}`, "MicroAPI");
|
|
173
|
+
reject(error);
|
|
174
|
+
});
|
|
164
175
|
});
|
|
165
176
|
}
|
|
166
177
|
}
|
package/package.json
CHANGED