@expressots/adapter-express 3.0.0-beta.2 → 3.0.0-beta.4
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
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
## [3.0.0-beta.4](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
|
+
|
|
7
|
+
### Tests
|
|
8
|
+
|
|
9
|
+
- update tests for globalConfiguration, isDevelopment, getHttpServer, serverShutdown ([17b7d92](https://github.com/expressots/adapter-express/commit/17b7d92e87f4ad0d14a386e8351c723e1392a5c3))
|
|
10
|
+
|
|
11
|
+
## [3.0.0-beta.3](https://github.com/expressots/adapter-express/compare/3.0.0-beta.2...3.0.0) (2024-11-28)
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
- create server instance http and add close method for graceful shutdown ([be16011](https://github.com/expressots/adapter-express/commit/be16011f4686ce513bc254b8db9ca8abe2d79324))
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
- update error message in getHttpServer method for clarity ([dc4f5a3](https://github.com/expressots/adapter-express/commit/dc4f5a30322e00efa74283445d1d46fabb61ffe1))
|
|
20
|
+
- update middleware path handling to include global prefix ([b7bffc5](https://github.com/expressots/adapter-express/commit/b7bffc5d2217ace1097ee7ef28dc28176de8e256))
|
|
21
|
+
|
|
22
|
+
### Tests
|
|
23
|
+
|
|
24
|
+
- add unit tests for serverShutdown and setGlobalRoutePrefix methods ([2c1ad63](https://github.com/expressots/adapter-express/commit/2c1ad633f33374d09c3b8ea2b004cdc94f207da7))
|
|
25
|
+
|
|
1
26
|
## [3.0.0-beta.2](https://github.com/expressots/adapter-express/compare/3.0.0-beta.1...3.0.0) (2024-11-24)
|
|
2
27
|
|
|
3
28
|
### Features
|
|
@@ -31,7 +31,6 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
31
31
|
const process_1 = __importStar(require("process"));
|
|
32
32
|
const core_1 = require("@expressots/core");
|
|
33
33
|
const shared_1 = require("@expressots/shared");
|
|
34
|
-
const application_express_base_1 = require("./application-express.base");
|
|
35
34
|
const http_status_middleware_1 = require("./express-utils/http-status-middleware");
|
|
36
35
|
const inversify_express_server_1 = require("./express-utils/inversify-express-server");
|
|
37
36
|
const engine_1 = require("./render/engine");
|
|
@@ -46,25 +45,63 @@ const engine_1 = require("./render/engine");
|
|
|
46
45
|
* @method setEngine - Configures the application's view engine based on the provided configuration options.
|
|
47
46
|
* @method isDevelopment - Verifies if the current environment is development.
|
|
48
47
|
*/
|
|
49
|
-
class AppExpress
|
|
48
|
+
class AppExpress {
|
|
50
49
|
constructor() {
|
|
51
|
-
super();
|
|
52
50
|
this.logger = new core_1.Logger();
|
|
53
51
|
this.console = new core_1.Console();
|
|
52
|
+
this.serverInstance = null;
|
|
54
53
|
this.globalPrefix = "/";
|
|
55
54
|
this.middlewares = [];
|
|
56
55
|
this.renderOptions = {};
|
|
57
56
|
this.globalConfiguration();
|
|
58
57
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Implement this method to set up global configurations for the server.
|
|
60
|
+
* This method is called before any other server initialization methods.
|
|
61
|
+
* Use this method to configure global settings that apply to the entire
|
|
62
|
+
* server application. Supports asynchronous setup with a Promise.
|
|
63
|
+
*
|
|
64
|
+
* @abstract
|
|
65
|
+
* @returns {void | Promise<void>}
|
|
66
|
+
* @public API
|
|
67
|
+
*/
|
|
68
|
+
async globalConfiguration() { }
|
|
69
|
+
/**
|
|
70
|
+
* Implement this method to set up required services or configurations before
|
|
71
|
+
* the server starts. This is essential for initializing dependencies or settings
|
|
72
|
+
* necessary for server operation. Supports asynchronous setup with a Promise.
|
|
73
|
+
*
|
|
74
|
+
* @abstract
|
|
75
|
+
* @returns {void | Promise<void>}
|
|
76
|
+
* @public API
|
|
77
|
+
*/
|
|
78
|
+
async configureServices() { }
|
|
79
|
+
/**
|
|
80
|
+
* Implement this method to execute actions or configurations after the server
|
|
81
|
+
* has started. Use this for operations that need to run once the server is
|
|
82
|
+
* operational. Supports asynchronous execution with a Promise.
|
|
83
|
+
*
|
|
84
|
+
* @abstract
|
|
85
|
+
* @returns {void | Promise<void>}
|
|
86
|
+
* @public API
|
|
87
|
+
*/
|
|
88
|
+
async postServerInitialization() { }
|
|
89
|
+
/**
|
|
90
|
+
* Implement this method to handle cleanup and final actions when the server
|
|
91
|
+
* is shutting down. Ideal for closing resources, stopping tasks, or other
|
|
92
|
+
* cleanup procedures to ensure a graceful server shutdown. Supports asynchronous
|
|
93
|
+
* cleanup with a Promise.
|
|
94
|
+
*
|
|
95
|
+
* @abstract
|
|
96
|
+
* @returns {void | Promise<void>}
|
|
97
|
+
* @public API
|
|
98
|
+
*/
|
|
99
|
+
async serverShutdown() { }
|
|
63
100
|
/**
|
|
64
101
|
* Handles process exit by calling serverShutdown and then exiting the process.
|
|
65
102
|
*/
|
|
66
|
-
handleExit() {
|
|
67
|
-
this.serverShutdown();
|
|
103
|
+
async handleExit() {
|
|
104
|
+
await this.serverShutdown();
|
|
68
105
|
process_1.default.exit(0);
|
|
69
106
|
}
|
|
70
107
|
/**
|
|
@@ -118,15 +155,16 @@ class AppExpress extends application_express_base_1.ApplicationBase {
|
|
|
118
155
|
}
|
|
119
156
|
else if (entry?.hasOwnProperty("path")) {
|
|
120
157
|
const { path, middlewares } = entry;
|
|
158
|
+
const pathGlobal = this.globalPrefix + path;
|
|
121
159
|
for (const mid of middlewares) {
|
|
122
160
|
if (path) {
|
|
123
161
|
if (typeof mid === "function") {
|
|
124
|
-
app.use(
|
|
162
|
+
app.use(pathGlobal, mid);
|
|
125
163
|
}
|
|
126
164
|
else {
|
|
127
165
|
const middleware = mid;
|
|
128
166
|
middleware.use = middleware.use.bind(middleware);
|
|
129
|
-
app.use(
|
|
167
|
+
app.use(pathGlobal, middleware.use);
|
|
130
168
|
}
|
|
131
169
|
}
|
|
132
170
|
}
|
|
@@ -181,13 +219,14 @@ class AppExpress extends application_express_base_1.ApplicationBase {
|
|
|
181
219
|
this.environment = this.environment || "development";
|
|
182
220
|
this.app.set("env", this.environment);
|
|
183
221
|
this.port = typeof port === "string" ? parseInt(port, 10) : port || 3000;
|
|
184
|
-
this.app.listen(this.port, () => {
|
|
222
|
+
this.serverInstance = this.app.listen(this.port, () => {
|
|
185
223
|
this.console.messageServer(this.port, this.environment, appInfo);
|
|
186
224
|
["SIGTERM", "SIGHUP", "SIGBREAK", "SIGQUIT", "SIGINT"].forEach((signal) => {
|
|
187
225
|
process_1.default.on(signal, this.handleExit.bind(this));
|
|
188
226
|
});
|
|
189
227
|
});
|
|
190
228
|
await this.postServerInitialization();
|
|
229
|
+
return this;
|
|
191
230
|
}
|
|
192
231
|
/**
|
|
193
232
|
* Sets the global route prefix for the application.
|
|
@@ -195,7 +234,7 @@ class AppExpress extends application_express_base_1.ApplicationBase {
|
|
|
195
234
|
* @param {string} prefix - The prefix to use for all routes.
|
|
196
235
|
* @public API
|
|
197
236
|
*/
|
|
198
|
-
setGlobalRoutePrefix(prefix) {
|
|
237
|
+
async setGlobalRoutePrefix(prefix) {
|
|
199
238
|
this.globalPrefix = prefix;
|
|
200
239
|
}
|
|
201
240
|
/**
|
|
@@ -245,7 +284,7 @@ class AppExpress extends application_express_base_1.ApplicationBase {
|
|
|
245
284
|
* @returns A boolean value indicating whether the current environment is development or not.
|
|
246
285
|
* @public API
|
|
247
286
|
*/
|
|
248
|
-
isDevelopment() {
|
|
287
|
+
async isDevelopment() {
|
|
249
288
|
if (this.app) {
|
|
250
289
|
return this.app.get("env") === "development";
|
|
251
290
|
}
|
|
@@ -268,7 +307,7 @@ class AppExpress extends application_express_base_1.ApplicationBase {
|
|
|
268
307
|
* ```
|
|
269
308
|
* @public API
|
|
270
309
|
*/
|
|
271
|
-
initEnvironment(environment, options) {
|
|
310
|
+
async initEnvironment(environment, options) {
|
|
272
311
|
this.environment = environment;
|
|
273
312
|
if (options === undefined) {
|
|
274
313
|
(0, shared_1.config)({ path: ".env" });
|
|
@@ -296,11 +335,11 @@ class AppExpress extends application_express_base_1.ApplicationBase {
|
|
|
296
335
|
* @public API
|
|
297
336
|
*/
|
|
298
337
|
async getHttpServer() {
|
|
299
|
-
if (!this.
|
|
300
|
-
this.logger.error("
|
|
301
|
-
throw new Error("
|
|
338
|
+
if (!this.serverInstance) {
|
|
339
|
+
this.logger.error("Server instance not initialized yet", "adapter-express");
|
|
340
|
+
throw new Error("Server instance not initialized yet");
|
|
302
341
|
}
|
|
303
|
-
return this.
|
|
342
|
+
return Promise.resolve(this.serverInstance);
|
|
304
343
|
}
|
|
305
344
|
}
|
|
306
345
|
exports.AppExpress = AppExpress;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { AppContainer, IConsoleMessage,
|
|
3
|
-
import {
|
|
1
|
+
import { Server as HTTPServer } from "http";
|
|
2
|
+
import { AppContainer, IConsoleMessage, IMiddleware, ProviderManager } from "@expressots/core";
|
|
3
|
+
import { Env, IWebServerPublic, RenderEngine, Server } from "@expressots/shared";
|
|
4
4
|
import { interfaces } from "../di/di.interfaces";
|
|
5
|
-
import { ApplicationBase } from "./application-express.base";
|
|
6
5
|
/**
|
|
7
6
|
* The AppExpress class provides methods for configuring and running an Express application.
|
|
8
7
|
* @class AppExpress
|
|
@@ -14,10 +13,11 @@ import { ApplicationBase } from "./application-express.base";
|
|
|
14
13
|
* @method setEngine - Configures the application's view engine based on the provided configuration options.
|
|
15
14
|
* @method isDevelopment - Verifies if the current environment is development.
|
|
16
15
|
*/
|
|
17
|
-
export declare class AppExpress
|
|
16
|
+
export declare class AppExpress implements Server.IWebServer {
|
|
18
17
|
private logger;
|
|
19
18
|
private console;
|
|
20
19
|
private app;
|
|
20
|
+
private serverInstance;
|
|
21
21
|
private port;
|
|
22
22
|
private environment?;
|
|
23
23
|
private appContainer;
|
|
@@ -27,10 +27,48 @@ export declare class AppExpress extends ApplicationBase implements Server.IWebSe
|
|
|
27
27
|
private providerManager;
|
|
28
28
|
private renderOptions;
|
|
29
29
|
constructor();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Implement this method to set up global configurations for the server.
|
|
32
|
+
* This method is called before any other server initialization methods.
|
|
33
|
+
* Use this method to configure global settings that apply to the entire
|
|
34
|
+
* server application. Supports asynchronous setup with a Promise.
|
|
35
|
+
*
|
|
36
|
+
* @abstract
|
|
37
|
+
* @returns {void | Promise<void>}
|
|
38
|
+
* @public API
|
|
39
|
+
*/
|
|
40
|
+
protected globalConfiguration(): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Implement this method to set up required services or configurations before
|
|
43
|
+
* the server starts. This is essential for initializing dependencies or settings
|
|
44
|
+
* necessary for server operation. Supports asynchronous setup with a Promise.
|
|
45
|
+
*
|
|
46
|
+
* @abstract
|
|
47
|
+
* @returns {void | Promise<void>}
|
|
48
|
+
* @public API
|
|
49
|
+
*/
|
|
50
|
+
protected configureServices(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Implement this method to execute actions or configurations after the server
|
|
53
|
+
* has started. Use this for operations that need to run once the server is
|
|
54
|
+
* operational. Supports asynchronous execution with a Promise.
|
|
55
|
+
*
|
|
56
|
+
* @abstract
|
|
57
|
+
* @returns {void | Promise<void>}
|
|
58
|
+
* @public API
|
|
59
|
+
*/
|
|
60
|
+
protected postServerInitialization(): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Implement this method to handle cleanup and final actions when the server
|
|
63
|
+
* is shutting down. Ideal for closing resources, stopping tasks, or other
|
|
64
|
+
* cleanup procedures to ensure a graceful server shutdown. Supports asynchronous
|
|
65
|
+
* cleanup with a Promise.
|
|
66
|
+
*
|
|
67
|
+
* @abstract
|
|
68
|
+
* @returns {void | Promise<void>}
|
|
69
|
+
* @public API
|
|
70
|
+
*/
|
|
71
|
+
protected serverShutdown(): Promise<void>;
|
|
34
72
|
/**
|
|
35
73
|
* Handles process exit by calling serverShutdown and then exiting the process.
|
|
36
74
|
*/
|
|
@@ -78,14 +116,14 @@ export declare class AppExpress extends ApplicationBase implements Server.IWebSe
|
|
|
78
116
|
* @param appInfo - Optional message to display the app name and version.
|
|
79
117
|
* @public API
|
|
80
118
|
*/
|
|
81
|
-
listen(port: number | string, appInfo?: IConsoleMessage): Promise<
|
|
119
|
+
listen(port: number | string, appInfo?: IConsoleMessage): Promise<IWebServerPublic>;
|
|
82
120
|
/**
|
|
83
121
|
* Sets the global route prefix for the application.
|
|
84
122
|
* @method setGlobalRoutePrefix
|
|
85
123
|
* @param {string} prefix - The prefix to use for all routes.
|
|
86
124
|
* @public API
|
|
87
125
|
*/
|
|
88
|
-
setGlobalRoutePrefix(prefix: string): void
|
|
126
|
+
setGlobalRoutePrefix(prefix: string): Promise<void>;
|
|
89
127
|
/**
|
|
90
128
|
* Configures the application's view engine based on the provided configuration options.
|
|
91
129
|
*/
|
|
@@ -105,7 +143,7 @@ export declare class AppExpress extends ApplicationBase implements Server.IWebSe
|
|
|
105
143
|
* @returns A boolean value indicating whether the current environment is development or not.
|
|
106
144
|
* @public API
|
|
107
145
|
*/
|
|
108
|
-
|
|
146
|
+
isDevelopment(): Promise<boolean>;
|
|
109
147
|
/**
|
|
110
148
|
* Load environment variables from the specified file based on the environment configuration.
|
|
111
149
|
* @param environment - The environment to load configuration for.
|
|
@@ -122,11 +160,11 @@ export declare class AppExpress extends ApplicationBase implements Server.IWebSe
|
|
|
122
160
|
* ```
|
|
123
161
|
* @public API
|
|
124
162
|
*/
|
|
125
|
-
initEnvironment(environment: Env.Environment, options?: Env.IEnvironment): void
|
|
163
|
+
initEnvironment(environment: Env.Environment, options?: Env.IEnvironment): Promise<void>;
|
|
126
164
|
/**
|
|
127
165
|
* Get the underlying HTTP server. (default: Express.js)
|
|
128
166
|
* @returns The underlying HTTP server after initialization.
|
|
129
167
|
* @public API
|
|
130
168
|
*/
|
|
131
|
-
getHttpServer(): Promise<
|
|
169
|
+
getHttpServer(): Promise<HTTPServer>;
|
|
132
170
|
}
|
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/adapter-express",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.4",
|
|
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",
|
|
@@ -67,14 +66,14 @@
|
|
|
67
66
|
"reflect-metadata": "0.2.2"
|
|
68
67
|
},
|
|
69
68
|
"devDependencies": {
|
|
70
|
-
"@codecov/vite-plugin": "
|
|
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": "
|
|
74
|
-
"@expressots/shared": "0.
|
|
72
|
+
"@expressots/core": "3.0.0-beta.4",
|
|
73
|
+
"@expressots/shared": "3.0.0-beta.4",
|
|
75
74
|
"@release-it/conventional-changelog": "8.0.1",
|
|
76
75
|
"@types/express": "4.17.21",
|
|
77
|
-
"@types/jest": "
|
|
76
|
+
"@types/jest": "29.5.14",
|
|
78
77
|
"@types/node": "20.14.10",
|
|
79
78
|
"@typescript-eslint/eslint-plugin": "7.16.1",
|
|
80
79
|
"@typescript-eslint/parser": "7.16.1",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/adapter-express",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.4",
|
|
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",
|
|
@@ -67,14 +66,14 @@
|
|
|
67
66
|
"reflect-metadata": "0.2.2"
|
|
68
67
|
},
|
|
69
68
|
"devDependencies": {
|
|
70
|
-
"@codecov/vite-plugin": "
|
|
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": "
|
|
74
|
-
"@expressots/shared": "0.
|
|
72
|
+
"@expressots/core": "3.0.0-beta.4",
|
|
73
|
+
"@expressots/shared": "3.0.0-beta.4",
|
|
75
74
|
"@release-it/conventional-changelog": "8.0.1",
|
|
76
75
|
"@types/express": "4.17.21",
|
|
77
|
-
"@types/jest": "
|
|
76
|
+
"@types/jest": "29.5.14",
|
|
78
77
|
"@types/node": "20.14.10",
|
|
79
78
|
"@typescript-eslint/eslint-plugin": "7.16.1",
|
|
80
79
|
"@typescript-eslint/parser": "7.16.1",
|