@expressots/adapter-express 1.1.1 → 1.2.0
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,5 +1,15 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## [1.2.0](https://github.com/expressots/adapter-express/compare/1.1.1...1.2.0) (2024-3-5)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add expressots middleware support ([809f148](https://github.com/expressots/adapter-express/commit/809f148a2b9a6bb0aa41f231595b3a4c394574ee))
|
|
9
|
+
* bump @commitlint/cli from 17.8.1 to 18.0.0 ([15fbb1a](https://github.com/expressots/adapter-express/commit/15fbb1a84c758df25b60f2a893fd44829db3c0dc))
|
|
10
|
+
* fix middleware binding to constructor ([3a6f7dc](https://github.com/expressots/adapter-express/commit/3a6f7dca40889133b09630582c775156392c4fd7))
|
|
11
|
+
* fix path call on expresso middleware ([934ae17](https://github.com/expressots/adapter-express/commit/934ae17110489315536e28b71cde24f5f18d88dc))
|
|
12
|
+
|
|
3
13
|
## [1.1.1](https://github.com/expressots/adapter-express/compare/1.1.0...1.1.1) (2023-10-10)
|
|
4
14
|
|
|
5
15
|
|
|
@@ -24,6 +24,16 @@ const process_1 = __importDefault(require("process"));
|
|
|
24
24
|
const core_1 = require("@expressots/core");
|
|
25
25
|
const inversify_express_server_1 = require("./express-utils/inversify-express-server");
|
|
26
26
|
const application_base_1 = require("./application-base");
|
|
27
|
+
/**
|
|
28
|
+
* Abstract class for creating custom Expresso middleware.
|
|
29
|
+
* Custom middleware classes should extend this class and implement the use method.
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
class ExpressoMiddleware {
|
|
33
|
+
get name() {
|
|
34
|
+
return this.constructor.name;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
27
37
|
/**
|
|
28
38
|
* Enum representing possible server environments.
|
|
29
39
|
*/
|
|
@@ -51,6 +61,41 @@ let ApplicationExpress = class ApplicationExpress extends application_base_1.App
|
|
|
51
61
|
this.serverShutdown();
|
|
52
62
|
process_1.default.exit(0);
|
|
53
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Configures the Express application with the provided middleware entries.
|
|
66
|
+
* @param app - The Express application instance.
|
|
67
|
+
* @param middlewareEntries - An array of Express middleware entries to be applied.
|
|
68
|
+
*/
|
|
69
|
+
configureMiddleware(app, middlewareEntries) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
for (const entry of middlewareEntries) {
|
|
72
|
+
if (typeof entry === "function") {
|
|
73
|
+
app.use(entry);
|
|
74
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
75
|
+
}
|
|
76
|
+
else if (entry === null || entry === void 0 ? void 0 : entry.hasOwnProperty("path")) {
|
|
77
|
+
const { path, middlewares } = entry;
|
|
78
|
+
for (const mid of middlewares) {
|
|
79
|
+
if (path) {
|
|
80
|
+
if (typeof mid === "function") {
|
|
81
|
+
app.use(path, mid);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const middleware = mid;
|
|
85
|
+
middleware.use = middleware.use.bind(middleware);
|
|
86
|
+
app.use(path, middleware.use);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
const middleware = entry;
|
|
93
|
+
middleware.use = middleware.use.bind(middleware);
|
|
94
|
+
app.use(middleware.use);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
54
99
|
/**
|
|
55
100
|
* Create and configure the Express application.
|
|
56
101
|
* @param container - The InversifyJS container.
|
|
@@ -59,32 +104,16 @@ let ApplicationExpress = class ApplicationExpress extends application_base_1.App
|
|
|
59
104
|
*/
|
|
60
105
|
init(container, middlewares = []) {
|
|
61
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
yield
|
|
107
|
+
yield this.configureServices();
|
|
63
108
|
const middleware = container.get(core_1.Middleware);
|
|
64
109
|
const sortedMiddlewarePipeline = middleware.getMiddlewarePipeline();
|
|
65
110
|
const pipeline = sortedMiddlewarePipeline.map((entry) => entry.middleware);
|
|
66
111
|
this.middlewares.push(...middlewares, ...pipeline);
|
|
67
|
-
const allMiddlewareEntries = [...this.middlewares];
|
|
68
112
|
const expressServer = new inversify_express_server_1.InversifyExpressServer(container, null, {
|
|
69
113
|
rootPath: this.globalPrefix,
|
|
70
114
|
});
|
|
71
115
|
expressServer.setConfig((app) => {
|
|
72
|
-
|
|
73
|
-
if (typeof entry === "function") {
|
|
74
|
-
app.use(entry);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
const { path, middlewares } = entry;
|
|
78
|
-
middlewares.forEach((middleware) => {
|
|
79
|
-
if (path) {
|
|
80
|
-
app.use(path, middleware);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
app.use(middleware);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
});
|
|
116
|
+
this.configureMiddleware(app, this.middlewares);
|
|
88
117
|
});
|
|
89
118
|
expressServer.setErrorConfig((app) => {
|
|
90
119
|
if (middleware.getErrorHandler()) {
|
|
@@ -3,6 +3,16 @@ import { Container } from "inversify";
|
|
|
3
3
|
import { IApplicationMessageToConsole, RenderTemplateOptions } from "@expressots/core";
|
|
4
4
|
import { IApplicationExpress } from "./application-express.interface";
|
|
5
5
|
import { ApplicationBase } from "./application-base";
|
|
6
|
+
/**
|
|
7
|
+
* ExpressHandler Type
|
|
8
|
+
*
|
|
9
|
+
* The ExpressHandler type is a union type that represents various types of Express middleware functions.
|
|
10
|
+
* It can be one of the following types:
|
|
11
|
+
* - express.ErrorRequestHandler: Handles errors in the middleware pipeline.
|
|
12
|
+
* - express.RequestParamHandler: Handles parameters in the middleware pipeline.
|
|
13
|
+
* - express.RequestHandler: General request handler.
|
|
14
|
+
* - undefined: Represents the absence of a handler.
|
|
15
|
+
*/
|
|
6
16
|
type ExpressHandler = express.ErrorRequestHandler | express.RequestParamHandler | express.RequestHandler | undefined;
|
|
7
17
|
/**
|
|
8
18
|
* Enum representing possible server environments.
|
|
@@ -29,6 +39,12 @@ declare class ApplicationExpress extends ApplicationBase implements IApplication
|
|
|
29
39
|
* Handles process exit by calling serverShutdown and then exiting the process.
|
|
30
40
|
*/
|
|
31
41
|
private handleExit;
|
|
42
|
+
/**
|
|
43
|
+
* Configures the Express application with the provided middleware entries.
|
|
44
|
+
* @param app - The Express application instance.
|
|
45
|
+
* @param middlewareEntries - An array of Express middleware entries to be applied.
|
|
46
|
+
*/
|
|
47
|
+
private configureMiddleware;
|
|
32
48
|
/**
|
|
33
49
|
* Create and configure the Express application.
|
|
34
50
|
* @param container - The InversifyJS container.
|
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/adapter-express",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@adapter-express)",
|
|
5
5
|
"author": "",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"reflect-metadata": "^0.1.13"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@commitlint/cli": "^
|
|
72
|
+
"@commitlint/cli": "^18.0.0",
|
|
73
73
|
"@commitlint/config-conventional": "^17.7.0",
|
|
74
74
|
"@expressots/core": "^2.2.0",
|
|
75
75
|
"@release-it/conventional-changelog": "^7.0.1",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/adapter-express",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@adapter-express)",
|
|
5
5
|
"author": "",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"reflect-metadata": "^0.1.13"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@commitlint/cli": "^
|
|
72
|
+
"@commitlint/cli": "^18.0.0",
|
|
73
73
|
"@commitlint/config-conventional": "^17.7.0",
|
|
74
74
|
"@expressots/core": "^2.2.0",
|
|
75
75
|
"@release-it/conventional-changelog": "^7.0.1",
|