@expressots/adapter-express 3.0.0-beta.4 → 3.0.0-beta.4.2
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.
- package/lib/CHANGELOG.md +24 -0
- package/lib/cjs/adapter-express/application-express.js +20 -7
- package/lib/cjs/adapter-express/micro-api/application-express-micro.js +15 -4
- package/lib/cjs/types/adapter-express/micro-api/application-express-micro.d.ts +2 -2
- package/lib/package.json +1 -1
- package/package.json +1 -1
package/lib/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
## [3.0.0-beta.4.2](https://github.com/expressots/adapter-express/compare/3.0.0-beta.3...3.0.0) (2024-12-03)
|
|
2
|
+
|
|
3
|
+
### Code Refactoring
|
|
4
|
+
|
|
5
|
+
- app express class with async methods ([5c9ea2b](https://github.com/expressots/adapter-express/commit/5c9ea2b6cac9fa6455d140c0d0ce052712fa8251))
|
|
6
|
+
- return http server on getHttp instead of app express ([e6646de](https://github.com/expressots/adapter-express/commit/e6646de4e76e0824f2365695fa936975553796d4))
|
|
7
|
+
- server listen accept 0 to set random port ([7a97cf1](https://github.com/expressots/adapter-express/commit/7a97cf1d769acb0b7cbcba651aea49137310aa76))
|
|
8
|
+
- update getHttpServer method to return http.Server instance ([98985e8](https://github.com/expressots/adapter-express/commit/98985e841d608c2f17a09cb88ef50462c5a3d066))
|
|
9
|
+
|
|
10
|
+
### Tests
|
|
11
|
+
|
|
12
|
+
- update tests for globalConfiguration, isDevelopment, getHttpServer, serverShutdown ([17b7d92](https://github.com/expressots/adapter-express/commit/17b7d92e87f4ad0d14a386e8351c723e1392a5c3))
|
|
13
|
+
|
|
14
|
+
## [3.0.0-beta.4.1](https://github.com/expressots/adapter-express/compare/3.0.0-beta.3...3.0.0) (2024-12-03)
|
|
15
|
+
|
|
16
|
+
### Code Refactoring
|
|
17
|
+
|
|
18
|
+
- app express class with async methods ([5c9ea2b](https://github.com/expressots/adapter-express/commit/5c9ea2b6cac9fa6455d140c0d0ce052712fa8251))
|
|
19
|
+
- server listen accept 0 to set random port ([7a97cf1](https://github.com/expressots/adapter-express/commit/7a97cf1d769acb0b7cbcba651aea49137310aa76))
|
|
20
|
+
|
|
21
|
+
### Tests
|
|
22
|
+
|
|
23
|
+
- update tests for globalConfiguration, isDevelopment, getHttpServer, serverShutdown ([17b7d92](https://github.com/expressots/adapter-express/commit/17b7d92e87f4ad0d14a386e8351c723e1392a5c3))
|
|
24
|
+
|
|
1
25
|
## [3.0.0-beta.4](https://github.com/expressots/adapter-express/compare/3.0.0-beta.3...3.0.0) (2024-12-03)
|
|
2
26
|
|
|
3
27
|
### Code Refactoring
|
|
@@ -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.
|
|
@@ -113,7 +113,7 @@ class AppExpressMicro {
|
|
|
113
113
|
* @public API
|
|
114
114
|
*/
|
|
115
115
|
getHttpServer() {
|
|
116
|
-
return this.
|
|
116
|
+
return this.httpServer;
|
|
117
117
|
}
|
|
118
118
|
/**
|
|
119
119
|
* Create a new instance of the Express Micro API adapter
|
|
@@ -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
|
+
this.httpServer = this.app.listen(normalizedPort, () => {
|
|
157
|
+
const address = this.httpServer.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
|
+
this.httpServer.on("error", (error) => {
|
|
172
|
+
logger.error(`Error starting server: ${error.message}`, "MicroAPI");
|
|
173
|
+
reject(error);
|
|
174
|
+
});
|
|
164
175
|
});
|
|
165
176
|
}
|
|
166
177
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IMiddleware, interfaces } from "@expressots/core";
|
|
2
2
|
import { Env, IConsoleMessage } from "@expressots/shared";
|
|
3
|
-
import
|
|
3
|
+
import { Server } from "http";
|
|
4
4
|
import { IIOC } from "./application-express-micro-container";
|
|
5
5
|
import { IRoute } from "./application-express-micro-route";
|
|
6
6
|
/**
|
|
@@ -38,7 +38,7 @@ export interface ICreateMicroAPI {
|
|
|
38
38
|
* @returns express.Application
|
|
39
39
|
* @public API
|
|
40
40
|
*/
|
|
41
|
-
getHttpServer():
|
|
41
|
+
getHttpServer(): Server;
|
|
42
42
|
/**
|
|
43
43
|
* Build the Web Server Micro API
|
|
44
44
|
* @returns IWebServerMicroAPI
|
package/lib/package.json
CHANGED
package/package.json
CHANGED