@expressots/adapter-express 3.0.0-beta.2 → 3.0.0-beta.3

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.
@@ -51,6 +51,7 @@ class AppExpress extends application_express_base_1.ApplicationBase {
51
51
  super();
52
52
  this.logger = new core_1.Logger();
53
53
  this.console = new core_1.Console();
54
+ this.serverInstance = null;
54
55
  this.globalPrefix = "/";
55
56
  this.middlewares = [];
56
57
  this.renderOptions = {};
@@ -118,15 +119,16 @@ class AppExpress extends application_express_base_1.ApplicationBase {
118
119
  }
119
120
  else if (entry?.hasOwnProperty("path")) {
120
121
  const { path, middlewares } = entry;
122
+ const pathGlobal = this.globalPrefix + path;
121
123
  for (const mid of middlewares) {
122
124
  if (path) {
123
125
  if (typeof mid === "function") {
124
- app.use(path, mid);
126
+ app.use(pathGlobal, mid);
125
127
  }
126
128
  else {
127
129
  const middleware = mid;
128
130
  middleware.use = middleware.use.bind(middleware);
129
- app.use(path, middleware.use);
131
+ app.use(pathGlobal, middleware.use);
130
132
  }
131
133
  }
132
134
  }
@@ -181,7 +183,7 @@ class AppExpress extends application_express_base_1.ApplicationBase {
181
183
  this.environment = this.environment || "development";
182
184
  this.app.set("env", this.environment);
183
185
  this.port = typeof port === "string" ? parseInt(port, 10) : port || 3000;
184
- this.app.listen(this.port, () => {
186
+ this.serverInstance = this.app.listen(this.port, () => {
185
187
  this.console.messageServer(this.port, this.environment, appInfo);
186
188
  ["SIGTERM", "SIGHUP", "SIGBREAK", "SIGQUIT", "SIGINT"].forEach((signal) => {
187
189
  process_1.default.on(signal, this.handleExit.bind(this));
@@ -297,10 +299,36 @@ class AppExpress extends application_express_base_1.ApplicationBase {
297
299
  */
298
300
  async getHttpServer() {
299
301
  if (!this.app) {
300
- this.logger.error("The method can only be called in `app.provider` or in e2e tests with supertest.", "adapter-express");
302
+ this.logger.error("The method can only be called in `app` or in e2e tests with supertest.", "adapter-express");
301
303
  throw new Error("Incorrect usage of `getHttpServer` method");
302
304
  }
303
305
  return this.app;
304
306
  }
307
+ /**
308
+ * Close the server instance.
309
+ * @returns A promise that resolves when the server is closed.
310
+ * @public API
311
+ */
312
+ close(enableLog = false) {
313
+ return new Promise((resolve, reject) => {
314
+ if (this.serverInstance) {
315
+ this.serverInstance.close((err) => {
316
+ if (err) {
317
+ if (enableLog)
318
+ this.logger.error(`Error closing server: ${err.message}`, "adapter-express");
319
+ reject(err);
320
+ }
321
+ else {
322
+ if (enableLog)
323
+ this.logger.info("Server closed successfully", "adapter-express");
324
+ resolve();
325
+ }
326
+ });
327
+ }
328
+ else {
329
+ resolve();
330
+ }
331
+ });
332
+ }
305
333
  }
306
334
  exports.AppExpress = AppExpress;
@@ -18,6 +18,7 @@ export declare class AppExpress extends ApplicationBase implements Server.IWebSe
18
18
  private logger;
19
19
  private console;
20
20
  private app;
21
+ private serverInstance;
21
22
  private port;
22
23
  private environment?;
23
24
  private appContainer;
@@ -129,4 +130,10 @@ export declare class AppExpress extends ApplicationBase implements Server.IWebSe
129
130
  * @public API
130
131
  */
131
132
  getHttpServer(): Promise<express.Application>;
133
+ /**
134
+ * Close the server instance.
135
+ * @returns A promise that resolves when the server is closed.
136
+ * @public API
137
+ */
138
+ close(enableLog?: boolean): Promise<void>;
132
139
  }
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressots/adapter-express",
3
- "version": "3.0.0-beta.2",
3
+ "version": "3.0.0-beta.3",
4
4
  "description": "Expressots - modern, fast, lightweight nodejs web framework (@adapter-express)",
5
5
  "author": "",
6
6
  "main": "./lib/cjs/index.js",
@@ -54,7 +54,6 @@
54
54
  "build:cjs": "tsc -p tsconfig.cjs.json",
55
55
  "release": "release-it",
56
56
  "prepublish": "npm run build && npm pack",
57
- "publish": "npm publish --tag latest",
58
57
  "test": "jest",
59
58
  "test:watch": "jest --watch",
60
59
  "coverage": "jest --coverage",
@@ -70,8 +69,8 @@
70
69
  "@codecov/vite-plugin": "^0.0.1-beta.6",
71
70
  "@commitlint/cli": "19.2.1",
72
71
  "@commitlint/config-conventional": "19.2.2",
73
- "@expressots/core": "^3.0.0-beta.1",
74
- "@expressots/shared": "0.2.0",
72
+ "@expressots/core": "3.0.0-beta.3",
73
+ "@expressots/shared": "3.0.0-beta.3",
75
74
  "@release-it/conventional-changelog": "8.0.1",
76
75
  "@types/express": "4.17.21",
77
76
  "@types/jest": "^29.5.14",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressots/adapter-express",
3
- "version": "3.0.0-beta.2",
3
+ "version": "3.0.0-beta.3",
4
4
  "description": "Expressots - modern, fast, lightweight nodejs web framework (@adapter-express)",
5
5
  "author": "",
6
6
  "main": "./lib/cjs/index.js",
@@ -54,7 +54,6 @@
54
54
  "build:cjs": "tsc -p tsconfig.cjs.json",
55
55
  "release": "release-it",
56
56
  "prepublish": "npm run build && npm pack",
57
- "publish": "npm publish --tag latest",
58
57
  "test": "jest",
59
58
  "test:watch": "jest --watch",
60
59
  "coverage": "jest --coverage",
@@ -70,8 +69,8 @@
70
69
  "@codecov/vite-plugin": "^0.0.1-beta.6",
71
70
  "@commitlint/cli": "19.2.1",
72
71
  "@commitlint/config-conventional": "19.2.2",
73
- "@expressots/core": "^3.0.0-beta.1",
74
- "@expressots/shared": "0.2.0",
72
+ "@expressots/core": "3.0.0-beta.3",
73
+ "@expressots/shared": "3.0.0-beta.3",
75
74
  "@release-it/conventional-changelog": "8.0.1",
76
75
  "@types/express": "4.17.21",
77
76
  "@types/jest": "^29.5.14",