jimpex 8.0.0 → 9.0.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/CHANGELOG.md +13 -0
- package/README.md +2 -2
- package/dist/app/index.d.mts +14 -0
- package/dist/app/index.d.ts +5 -4
- package/dist/app/index.js +4 -0
- package/dist/app/jimpex.d.mts +14 -0
- package/dist/app/jimpex.d.ts +3 -2
- package/dist/app/jimpex.js +225 -0
- package/dist/app/jimpex.js.map +1 -1
- package/dist/controllers/common/config.d.mts +79 -0
- package/dist/controllers/common/config.d.ts +3 -2
- package/dist/controllers/common/config.js +18 -0
- package/dist/controllers/common/config.js.map +1 -1
- package/dist/controllers/common/health.d.mts +83 -0
- package/dist/controllers/common/health.d.ts +4 -3
- package/dist/controllers/common/health.js +18 -0
- package/dist/controllers/common/health.js.map +1 -1
- package/dist/controllers/common/index.d.mts +21 -0
- package/dist/controllers/common/index.d.ts +4 -4
- package/dist/controllers/common/index.js +6 -0
- package/dist/controllers/common/statics.d.mts +215 -0
- package/dist/controllers/common/statics.d.ts +4 -4
- package/dist/controllers/common/statics.js +51 -0
- package/dist/controllers/common/statics.js.map +1 -1
- package/dist/controllers/index.d.mts +24 -0
- package/dist/controllers/index.d.ts +4 -4
- package/dist/controllers/index.js +5 -0
- package/dist/controllers/utils/gateway.d.mts +725 -0
- package/dist/controllers/utils/gateway.d.ts +4 -3
- package/dist/controllers/utils/gateway.js +152 -0
- package/dist/controllers/utils/gateway.js.map +1 -1
- package/dist/controllers/utils/index.d.mts +17 -0
- package/dist/controllers/utils/index.d.ts +4 -3
- package/dist/controllers/utils/index.js +4 -0
- package/dist/esm/app/jimpex.js +222 -1
- package/dist/esm/app/jimpex.js.map +1 -1
- package/dist/esm/{chunk-T2T6Q22Z.js → chunk-2B2CG5KL.js} +1 -1
- package/dist/esm/controllers/common/config.js +19 -1
- package/dist/esm/controllers/common/config.js.map +1 -1
- package/dist/esm/controllers/common/health.js +19 -1
- package/dist/esm/controllers/common/health.js.map +1 -1
- package/dist/esm/controllers/common/statics.js +48 -1
- package/dist/esm/controllers/common/statics.js.map +1 -1
- package/dist/esm/controllers/utils/gateway.js +153 -1
- package/dist/esm/controllers/utils/gateway.js.map +1 -1
- package/dist/esm/middlewares/common/errorHandler.js +25 -1
- package/dist/esm/middlewares/common/errorHandler.js.map +1 -1
- package/dist/esm/middlewares/common/forceHTTPS.js +13 -1
- package/dist/esm/middlewares/common/forceHTTPS.js.map +1 -1
- package/dist/esm/middlewares/common/hsts.js +22 -1
- package/dist/esm/middlewares/common/hsts.js.map +1 -1
- package/dist/esm/middlewares/html/fastHTML.js +55 -1
- package/dist/esm/middlewares/html/fastHTML.js.map +1 -1
- package/dist/esm/middlewares/html/showHTML.js +33 -1
- package/dist/esm/middlewares/html/showHTML.js.map +1 -1
- package/dist/esm/middlewares/utils/versionValidator.js +35 -1
- package/dist/esm/middlewares/utils/versionValidator.js.map +1 -1
- package/dist/esm/services/common/appError.js +48 -2
- package/dist/esm/services/common/appError.js.map +1 -1
- package/dist/esm/services/common/httpError.js +10 -1
- package/dist/esm/services/common/httpError.js.map +1 -1
- package/dist/esm/services/common/index.js +1 -1
- package/dist/esm/services/common/sendFile.js +1 -1
- package/dist/esm/services/frontend/frontendFs.js +29 -1
- package/dist/esm/services/frontend/frontendFs.js.map +1 -1
- package/dist/esm/services/frontend/index.js +1 -1
- package/dist/esm/services/html/htmlGenerator.js +51 -1
- package/dist/esm/services/html/htmlGenerator.js.map +1 -1
- package/dist/esm/services/html/index.js +1 -1
- package/dist/esm/services/http/apiClient.js +27 -1
- package/dist/esm/services/http/apiClient.js.map +1 -1
- package/dist/esm/services/http/http.js +50 -1
- package/dist/esm/services/http/http.js.map +1 -1
- package/dist/esm/services/http/index.js +1 -1
- package/dist/esm/services/http/responsesBuilder.js +49 -2
- package/dist/esm/services/http/responsesBuilder.js.map +1 -1
- package/dist/esm/services/utils/ensureBearerToken.js +17 -1
- package/dist/esm/services/utils/ensureBearerToken.js.map +1 -1
- package/dist/esm/services/utils/index.js +1 -1
- package/dist/esm/utils/fns/others.js +1 -1
- package/dist/esm/utils/fns/routes.js +1 -1
- package/dist/esm/utils/fns/routes.js.map +1 -1
- package/dist/esm/utils/fns/statuses.js +1 -1
- package/dist/esm/utils/fns/text.js +1 -1
- package/dist/esm/utils/wrappers.js +1 -1
- package/dist/{jimpex-7eaee271.d.ts → index-b2a04c78.d.ts} +9 -5
- package/dist/index-efeb437e.d.ts +1282 -0
- package/dist/index.d.mts +46 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -0
- package/dist/middlewares/common/errorHandler.d.mts +132 -0
- package/dist/middlewares/common/errorHandler.d.ts +4 -3
- package/dist/middlewares/common/errorHandler.js +24 -0
- package/dist/middlewares/common/errorHandler.js.map +1 -1
- package/dist/middlewares/common/forceHTTPS.d.mts +69 -0
- package/dist/middlewares/common/forceHTTPS.d.ts +5 -4
- package/dist/middlewares/common/forceHTTPS.js +12 -0
- package/dist/middlewares/common/forceHTTPS.js.map +1 -1
- package/dist/middlewares/common/hsts.d.mts +110 -0
- package/dist/middlewares/common/hsts.d.ts +5 -4
- package/dist/middlewares/common/hsts.js +21 -0
- package/dist/middlewares/common/hsts.js.map +1 -1
- package/dist/middlewares/common/index.d.mts +22 -0
- package/dist/middlewares/common/index.d.ts +4 -3
- package/dist/middlewares/common/index.js +6 -0
- package/dist/middlewares/html/fastHTML.d.mts +180 -0
- package/dist/middlewares/html/fastHTML.d.ts +4 -4
- package/dist/middlewares/html/fastHTML.js +54 -0
- package/dist/middlewares/html/fastHTML.js.map +1 -1
- package/dist/middlewares/html/index.d.mts +21 -0
- package/dist/middlewares/html/index.d.ts +4 -4
- package/dist/middlewares/html/index.js +5 -0
- package/dist/middlewares/html/showHTML.d.mts +127 -0
- package/dist/middlewares/html/showHTML.d.ts +4 -4
- package/dist/middlewares/html/showHTML.js +32 -0
- package/dist/middlewares/html/showHTML.js.map +1 -1
- package/dist/middlewares/index.d.mts +30 -0
- package/dist/middlewares/index.d.ts +4 -4
- package/dist/middlewares/index.js +6 -0
- package/dist/middlewares/utils/index.d.mts +20 -0
- package/dist/middlewares/utils/index.d.ts +4 -3
- package/dist/middlewares/utils/index.js +4 -0
- package/dist/middlewares/utils/versionValidator.d.mts +215 -0
- package/dist/middlewares/utils/versionValidator.d.ts +4 -3
- package/dist/middlewares/utils/versionValidator.js +34 -0
- package/dist/middlewares/utils/versionValidator.js.map +1 -1
- package/dist/services/common/appError.d.mts +139 -0
- package/dist/services/common/appError.d.ts +4 -3
- package/dist/services/common/appError.js +47 -1
- package/dist/services/common/appError.js.map +1 -1
- package/dist/services/common/httpError.d.mts +80 -0
- package/dist/services/common/httpError.d.ts +4 -3
- package/dist/services/common/httpError.js +9 -0
- package/dist/services/common/httpError.js.map +1 -1
- package/dist/services/common/index.d.mts +47 -0
- package/dist/services/common/index.d.ts +4 -4
- package/dist/services/common/index.js +4 -1
- package/dist/services/common/sendFile.d.mts +102 -0
- package/dist/services/common/sendFile.d.ts +3 -3
- package/dist/services/frontend/frontendFs.d.mts +96 -0
- package/dist/services/frontend/frontendFs.d.ts +3 -3
- package/dist/services/frontend/frontendFs.js +32 -0
- package/dist/services/frontend/frontendFs.js.map +1 -1
- package/dist/services/frontend/index.d.mts +40 -0
- package/dist/services/frontend/index.d.ts +4 -4
- package/dist/services/frontend/index.js +2 -1
- package/dist/services/html/htmlGenerator.d.mts +237 -0
- package/dist/services/html/htmlGenerator.d.ts +2 -2
- package/dist/services/html/htmlGenerator.js +50 -0
- package/dist/services/html/htmlGenerator.js.map +1 -1
- package/dist/services/html/index.d.mts +43 -0
- package/dist/services/html/index.d.ts +4 -4
- package/dist/services/html/index.js +2 -1
- package/dist/services/http/apiClient.d.mts +170 -0
- package/dist/services/http/apiClient.d.ts +4 -3
- package/dist/services/http/apiClient.js +26 -0
- package/dist/services/http/apiClient.js.map +1 -1
- package/dist/services/http/http.d.mts +176 -0
- package/dist/services/http/http.d.ts +4 -3
- package/dist/services/http/http.js +53 -0
- package/dist/services/http/http.js.map +1 -1
- package/dist/services/http/index.d.mts +51 -0
- package/dist/services/http/index.d.ts +4 -3
- package/dist/services/http/index.js +4 -1
- package/dist/services/http/responsesBuilder.d.mts +179 -0
- package/dist/services/http/responsesBuilder.d.ts +3 -2
- package/dist/services/http/responsesBuilder.js +48 -1
- package/dist/services/http/responsesBuilder.js.map +1 -1
- package/dist/services/index.d.mts +33 -0
- package/dist/services/index.d.ts +4 -4
- package/dist/services/index.js +8 -0
- package/dist/services/utils/ensureBearerToken.d.mts +158 -0
- package/dist/services/utils/ensureBearerToken.d.ts +5 -4
- package/dist/services/utils/ensureBearerToken.js +16 -0
- package/dist/services/utils/ensureBearerToken.js.map +1 -1
- package/dist/services/utils/index.d.mts +44 -0
- package/dist/services/utils/index.d.ts +4 -3
- package/dist/services/utils/index.js +2 -1
- package/dist/types/events.d.mts +14 -0
- package/dist/types/events.d.ts +5 -4
- package/dist/types/express.d.mts +10 -0
- package/dist/types/http.d.mts +79 -0
- package/dist/types/index.d.mts +14 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +9 -0
- package/dist/types/options.d.mts +14 -0
- package/dist/types/options.d.ts +4 -3
- package/dist/types/utils.d.mts +48 -0
- package/dist/types/wootils.d.mts +4 -0
- package/dist/utils/fns/index.d.mts +5 -0
- package/dist/utils/fns/index.js +7 -0
- package/dist/utils/fns/others.d.mts +17 -0
- package/dist/utils/fns/routes.d.mts +39 -0
- package/dist/utils/fns/routes.js.map +1 -1
- package/dist/utils/fns/statuses.d.mts +45 -0
- package/dist/utils/fns/statuses.js +4 -0
- package/dist/utils/fns/statuses.js.map +1 -1
- package/dist/utils/fns/text.d.mts +9 -0
- package/dist/utils/index.d.mts +19 -0
- package/dist/utils/index.d.ts +5 -4
- package/dist/utils/index.js +5 -0
- package/dist/utils/wrappers.d.mts +14 -0
- package/dist/utils/wrappers.d.ts +4 -3
- package/package.json +43 -43
- /package/dist/esm/{chunk-T2T6Q22Z.js.map → chunk-2B2CG5KL.js.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
# [9.0.0](https://github.com/homer0/jimpex/compare/8.0.0...9.0.0) (2023-10-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* drop Node 16 support ([5e81112](https://github.com/homer0/jimpex/commit/5e81112bacea1f74f5250c6b12c6f1f94badee7f))
|
|
7
|
+
* update dependencies ([543e232](https://github.com/homer0/jimpex/commit/543e232bad8a13f67f380997209140c65b6292c4))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### BREAKING CHANGES
|
|
11
|
+
|
|
12
|
+
* Node 16 is not longer supported. Node 18.17 is the minimum required version now.
|
|
13
|
+
|
|
1
14
|
# [8.0.0](https://github.com/homer0/jimpex/compare/7.0.2...8.0.0) (2022-12-28)
|
|
2
15
|
|
|
3
16
|
|
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Jimpex
|
|
2
2
|
|
|
3
|
-
[](https://img.shields.io/github/actions/workflow/status/homer0/jimpex/test.yml?branch=main&style=flat-square)](https://github.com/homer0/jimpex/actions/workflows/test.yml?query=branch%3Amain)
|
|
4
4
|
[](https://coveralls.io/github/homer0/jimpex?branch=main)
|
|
5
|
-

|
|
5
|
+

|
|
6
6
|
|
|
7
7
|
Express as dependency injection container.
|
|
8
8
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { J as Jimpex, j as jimpex } from '../index-efeb437e.js';
|
|
2
|
+
import '../types/express.mjs';
|
|
3
|
+
import 'express';
|
|
4
|
+
import '../types/http.mjs';
|
|
5
|
+
import 'https';
|
|
6
|
+
import 'http';
|
|
7
|
+
import 'spdy';
|
|
8
|
+
import 'node-fetch';
|
|
9
|
+
import '../types/utils.mjs';
|
|
10
|
+
import '@homer0/path-utils';
|
|
11
|
+
import '@homer0/simple-logger';
|
|
12
|
+
import '@homer0/simple-config';
|
|
13
|
+
import '@homer0/events-hub';
|
|
14
|
+
import '@homer0/jimple';
|
package/dist/app/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export { J as Jimpex, j as jimpex } from '../
|
|
2
|
-
import '@homer0/jimple';
|
|
3
|
-
import '@homer0/events-hub';
|
|
1
|
+
export { J as Jimpex, j as jimpex } from '../index-b2a04c78.js';
|
|
4
2
|
import '../types/express.js';
|
|
5
3
|
import 'express';
|
|
6
4
|
import '../types/http.js';
|
|
@@ -8,6 +6,9 @@ import 'https';
|
|
|
8
6
|
import 'http';
|
|
9
7
|
import 'spdy';
|
|
10
8
|
import 'node-fetch';
|
|
11
|
-
import '@homer0/simple-config';
|
|
12
9
|
import '../types/utils.js';
|
|
10
|
+
import '@homer0/path-utils';
|
|
13
11
|
import '@homer0/simple-logger';
|
|
12
|
+
import '@homer0/simple-config';
|
|
13
|
+
import '@homer0/events-hub';
|
|
14
|
+
import '@homer0/jimple';
|
package/dist/app/index.js
CHANGED
|
@@ -16,4 +16,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var app_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(app_exports);
|
|
18
18
|
__reExport(app_exports, require("./jimpex"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./jimpex")
|
|
22
|
+
});
|
|
19
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import '@homer0/jimple';
|
|
2
|
+
import '@homer0/events-hub';
|
|
3
|
+
export { J as Jimpex, j as jimpex } from '../index-efeb437e.js';
|
|
4
|
+
import 'express';
|
|
5
|
+
import '../types/http.mjs';
|
|
6
|
+
import '../types/utils.mjs';
|
|
7
|
+
import '@homer0/simple-logger';
|
|
8
|
+
import '@homer0/simple-config';
|
|
9
|
+
import '../types/express.mjs';
|
|
10
|
+
import '@homer0/path-utils';
|
|
11
|
+
import 'node-fetch';
|
|
12
|
+
import 'https';
|
|
13
|
+
import 'http';
|
|
14
|
+
import 'spdy';
|
package/dist/app/jimpex.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import '@homer0/jimple';
|
|
2
2
|
import '@homer0/events-hub';
|
|
3
|
-
export { J as Jimpex, j as jimpex } from '../
|
|
3
|
+
export { J as Jimpex, j as jimpex } from '../index-b2a04c78.js';
|
|
4
4
|
import 'express';
|
|
5
5
|
import '../types/http.js';
|
|
6
6
|
import '../types/utils.js';
|
|
7
7
|
import '@homer0/simple-logger';
|
|
8
8
|
import '@homer0/simple-config';
|
|
9
9
|
import '../types/express.js';
|
|
10
|
+
import '@homer0/path-utils';
|
|
11
|
+
import 'node-fetch';
|
|
10
12
|
import 'https';
|
|
11
13
|
import 'http';
|
|
12
14
|
import 'spdy';
|
|
13
|
-
import 'node-fetch';
|
package/dist/app/jimpex.js
CHANGED
|
@@ -19,6 +19,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
19
19
|
return to;
|
|
20
20
|
};
|
|
21
21
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
26
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
27
|
mod
|
|
24
28
|
));
|
|
@@ -53,14 +57,50 @@ var import_express = __toESM(require("express"));
|
|
|
53
57
|
var import_services = require("../services");
|
|
54
58
|
var import_utils = require("../utils");
|
|
55
59
|
class Jimpex extends import_jimple.Jimple {
|
|
60
|
+
/**
|
|
61
|
+
* @param options Preferences to customize the application.
|
|
62
|
+
* @param config The default settings for the configuration service. It's a
|
|
63
|
+
* shortcuit for `options.config.default`
|
|
64
|
+
*/
|
|
56
65
|
constructor(options = {}, config = {}) {
|
|
57
66
|
super();
|
|
67
|
+
/**
|
|
68
|
+
* The customization settings for the application.
|
|
69
|
+
*/
|
|
58
70
|
__publicField(this, "_options");
|
|
71
|
+
/**
|
|
72
|
+
* The Express application Jimpex uses under the hood.
|
|
73
|
+
*/
|
|
59
74
|
__publicField(this, "_express");
|
|
75
|
+
/**
|
|
76
|
+
* Since the configuration service has an async initialization, the class uses this flag
|
|
77
|
+
* internally to validate if the configuration has been initialized or not.
|
|
78
|
+
*/
|
|
60
79
|
__publicField(this, "_configReady", false);
|
|
80
|
+
/**
|
|
81
|
+
* A reference to the actuall HTTP the application will use. This can vary depending on
|
|
82
|
+
* whether HTTPS, or HTTP2 are enabled. If HTTPS is not enabled, it will be the same as
|
|
83
|
+
* the `express` property; if HTTPS is enabled, it will be an `https` server; and if
|
|
84
|
+
* HTTP2 is enabled, it will be an `spdy` server.
|
|
85
|
+
*/
|
|
61
86
|
__publicField(this, "_server");
|
|
87
|
+
/**
|
|
88
|
+
* The instance of the server that is listening for requests.
|
|
89
|
+
*/
|
|
62
90
|
__publicField(this, "_instance");
|
|
91
|
+
/**
|
|
92
|
+
* A list of functions that implement controllers and middlewares. When the application
|
|
93
|
+
* starts, the queue will be processed and those controllers and middlewares will be
|
|
94
|
+
* added to the server instance. The reason they are not added directly like with a
|
|
95
|
+
* regular Express implementation is that services on Jimple use lazy loading, and
|
|
96
|
+
* adding middlewares and controllers as they come could cause errors if they depend on
|
|
97
|
+
* services that are not yet registered.
|
|
98
|
+
*/
|
|
63
99
|
__publicField(this, "_mountQueue", []);
|
|
100
|
+
/**
|
|
101
|
+
* A list with all the top routes controlled by the application. Every time a controller
|
|
102
|
+
* is mounted, its route will be added here.
|
|
103
|
+
*/
|
|
64
104
|
__publicField(this, "_controlledRoutes", []);
|
|
65
105
|
this._options = (0, import_deep_assign.deepAssignWithOverwrite)(
|
|
66
106
|
{
|
|
@@ -111,12 +151,24 @@ class Jimpex extends import_jimple.Jimple {
|
|
|
111
151
|
this.boot();
|
|
112
152
|
}
|
|
113
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* This is where the app would register all its specific services, middlewares and controllers.
|
|
156
|
+
*/
|
|
114
157
|
boot() {
|
|
115
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Disables the server TLS validation. Meant to be used for development purposes.
|
|
161
|
+
*/
|
|
116
162
|
disableTLSValidation() {
|
|
117
163
|
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";
|
|
118
164
|
this.logger.warn("TLS validation has been disabled");
|
|
119
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Starts the app server.
|
|
168
|
+
*
|
|
169
|
+
* @param onStart A callback function to be called when the server actually starts.
|
|
170
|
+
* @returns The server instance.
|
|
171
|
+
*/
|
|
120
172
|
async start(onStart) {
|
|
121
173
|
await this._setupConfig();
|
|
122
174
|
const config = this.getConfig();
|
|
@@ -138,6 +190,17 @@ class Jimpex extends import_jimple.Jimple {
|
|
|
138
190
|
});
|
|
139
191
|
return this._instance;
|
|
140
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* This is an alias of `start`. The idea is for it to be used on serverless platforms,
|
|
195
|
+
* where you don't get to start your app, you just have export it.
|
|
196
|
+
*
|
|
197
|
+
* @param port In case the configuration doesn't already have it,
|
|
198
|
+
* this is the port where the application will use to run. If this
|
|
199
|
+
* parameter is used, the method will overwrite the `port`
|
|
200
|
+
* setting on the configuration service.
|
|
201
|
+
* @param onStart A callback function to be called when the server starts.
|
|
202
|
+
* @returns The server instance.
|
|
203
|
+
*/
|
|
141
204
|
async listen(port, onStart) {
|
|
142
205
|
if (port) {
|
|
143
206
|
await this._setupConfig();
|
|
@@ -146,6 +209,9 @@ class Jimpex extends import_jimple.Jimple {
|
|
|
146
209
|
}
|
|
147
210
|
return this.start(onStart);
|
|
148
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Stops the server instance.
|
|
214
|
+
*/
|
|
149
215
|
stop() {
|
|
150
216
|
if (!this._instance)
|
|
151
217
|
return;
|
|
@@ -154,6 +220,12 @@ class Jimpex extends import_jimple.Jimple {
|
|
|
154
220
|
this._instance = void 0;
|
|
155
221
|
this._emitEvent("afterStop", { app: this });
|
|
156
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Mounts a route controller or a middleware into a server routes.
|
|
225
|
+
*
|
|
226
|
+
* @param route The route for the controller/middleware.
|
|
227
|
+
* @param controller The controller/middleware resource to be mounted.
|
|
228
|
+
*/
|
|
157
229
|
mount(route, controller) {
|
|
158
230
|
let useController;
|
|
159
231
|
if ("register" in controller && typeof controller.register === "function" && controller.provider === true) {
|
|
@@ -180,6 +252,11 @@ class Jimpex extends import_jimple.Jimple {
|
|
|
180
252
|
this._controlledRoutes.push(route);
|
|
181
253
|
});
|
|
182
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* Adds a global middleware to the application.
|
|
257
|
+
*
|
|
258
|
+
* @param middleware The middleware resource to be added.
|
|
259
|
+
*/
|
|
183
260
|
use(middleware) {
|
|
184
261
|
const useMiddleware = "register" in middleware && typeof middleware.register === "function" ? middleware.register(this) : middleware;
|
|
185
262
|
this._mountQueue.push((server) => {
|
|
@@ -201,6 +278,15 @@ class Jimpex extends import_jimple.Jimple {
|
|
|
201
278
|
);
|
|
202
279
|
});
|
|
203
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Gets a setting from the configuration, or the configuration itself.
|
|
283
|
+
*
|
|
284
|
+
* @param setting The setting or settings to be retrieved. If is not specified, it
|
|
285
|
+
* will return the entire configuration.
|
|
286
|
+
* @param asArray If `true` and `setting` is an array, it will return the values as
|
|
287
|
+
* an array instead of an object.
|
|
288
|
+
* @template T The type of the setting to be retrieved.
|
|
289
|
+
*/
|
|
204
290
|
getConfig(setting, asArray = false) {
|
|
205
291
|
const config = this.try("config");
|
|
206
292
|
if (!config) {
|
|
@@ -211,41 +297,107 @@ class Jimpex extends import_jimple.Jimple {
|
|
|
211
297
|
}
|
|
212
298
|
return config.get(setting, asArray);
|
|
213
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* Creates a new router instance.
|
|
302
|
+
*/
|
|
214
303
|
getRouter() {
|
|
215
304
|
return this.get("router");
|
|
216
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* The logger service.
|
|
308
|
+
*/
|
|
217
309
|
get logger() {
|
|
218
310
|
return this.get("logger");
|
|
219
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* The Express application Jimpex uses under the hood.
|
|
314
|
+
*/
|
|
220
315
|
get express() {
|
|
221
316
|
return this._express;
|
|
222
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* The server instance that gets created when the app is started.
|
|
320
|
+
*/
|
|
223
321
|
get instance() {
|
|
224
322
|
return this._instance;
|
|
225
323
|
}
|
|
324
|
+
/**
|
|
325
|
+
* The application customization options.
|
|
326
|
+
*/
|
|
226
327
|
get options() {
|
|
227
328
|
return (0, import_deep_assign.deepAssignWithOverwrite)({}, this._options);
|
|
228
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* Gets the events service.
|
|
332
|
+
*/
|
|
229
333
|
get eventsHub() {
|
|
230
334
|
return this.get("events");
|
|
231
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* A list of the routes that have controllers mounted on them.
|
|
338
|
+
*/
|
|
232
339
|
get routes() {
|
|
233
340
|
return this._controlledRoutes.slice();
|
|
234
341
|
}
|
|
342
|
+
/**
|
|
343
|
+
* Adds a listener for an application event.
|
|
344
|
+
*
|
|
345
|
+
* @param eventName The name of the event to listen for.
|
|
346
|
+
* @param listener The listener function.
|
|
347
|
+
* @returns A function to unsubscribe the listener.
|
|
348
|
+
* @template EventName The name of the event, to match the type of the listener
|
|
349
|
+
* function.
|
|
350
|
+
*/
|
|
235
351
|
on(eventName, listener) {
|
|
236
352
|
return this.eventsHub.on(eventName, listener);
|
|
237
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* Adds a listener for an application event that will only be execuded once: the first
|
|
356
|
+
* time the event is triggered.
|
|
357
|
+
*
|
|
358
|
+
* @param eventName The name of the event to listen for.
|
|
359
|
+
* @param listener The listener function.
|
|
360
|
+
* @returns A function to unsubscribe the listener.
|
|
361
|
+
* @template EventName The name of the event, to match the type of the listener
|
|
362
|
+
* function.
|
|
363
|
+
*/
|
|
238
364
|
once(eventName, listener) {
|
|
239
365
|
return this.eventsHub.once(eventName, listener);
|
|
240
366
|
}
|
|
367
|
+
/**
|
|
368
|
+
* Based on the application options, it returns wheter the application is healthy or
|
|
369
|
+
* not.
|
|
370
|
+
*/
|
|
241
371
|
isHealthy() {
|
|
242
372
|
return this._options.healthCheck(this);
|
|
243
373
|
}
|
|
374
|
+
/**
|
|
375
|
+
* This method is like a "lifecycle method", it gets executed on the constructor right
|
|
376
|
+
* before the "boot step". The idea is for the method to be a helper when the
|
|
377
|
+
* application is defined by subclassing {@link Jimpex}: the application could register
|
|
378
|
+
* all important services here and the routes on boot, then, if the implementation needs
|
|
379
|
+
* to access or overwrite a something, it can send `boot: false`, access/register what
|
|
380
|
+
* it needs, and then call `boot()`. That would be impossible for an application without
|
|
381
|
+
* overwriting the constructor and the boot functionality.
|
|
382
|
+
*/
|
|
244
383
|
_init() {
|
|
245
384
|
}
|
|
385
|
+
/**
|
|
386
|
+
* It generates overwrites for the application options when it gets created. This method
|
|
387
|
+
* is a helper for when the application is defined by subclassing {@link Jimpex}: It's
|
|
388
|
+
* highly probable that if the application needs to change the default options, it would
|
|
389
|
+
* want to do it right from the class, instead of having to do it on every
|
|
390
|
+
* implementation. A way to do it would be overwriting the constructor and calling
|
|
391
|
+
* `super` with the custom overwrites, but this method exists so that won't be
|
|
392
|
+
* necessary: when creating the `options`, the constructor will merge the result of this
|
|
393
|
+
* method on top of the default ones.
|
|
394
|
+
*/
|
|
246
395
|
_initOptions() {
|
|
247
396
|
return {};
|
|
248
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* Registers the "core services" on the container: logger, events, utils, etc.
|
|
400
|
+
*/
|
|
249
401
|
_setupCoreServices() {
|
|
250
402
|
this.register(
|
|
251
403
|
(0, import_simple_logger.appLoggerProvider)({
|
|
@@ -266,6 +418,9 @@ class Jimpex extends import_jimple.Jimple {
|
|
|
266
418
|
this.set("events", () => new import_events_hub.EventsHub());
|
|
267
419
|
this.set("statuses", () => import_utils.statuses);
|
|
268
420
|
}
|
|
421
|
+
/**
|
|
422
|
+
* Configures the Express application based on the class options.
|
|
423
|
+
*/
|
|
269
424
|
_setupExpress() {
|
|
270
425
|
const { statics, filesizeLimit, express: expressOptions } = this._options;
|
|
271
426
|
if (expressOptions.trustProxy) {
|
|
@@ -301,6 +456,18 @@ class Jimpex extends import_jimple.Jimple {
|
|
|
301
456
|
this.factory(() => import_express.default.Router())
|
|
302
457
|
);
|
|
303
458
|
}
|
|
459
|
+
/**
|
|
460
|
+
* Adds a static folder to the application.
|
|
461
|
+
*
|
|
462
|
+
* @param route The route to add the folder to.
|
|
463
|
+
* @param folder The path to the folder in the file system. If not defined, it will
|
|
464
|
+
* be use the same value as `route`. The path could be relative to the
|
|
465
|
+
* project root, or where the application executable is located,
|
|
466
|
+
* depending on the value of the `onHome` parameter.
|
|
467
|
+
* @param onHome If `true`, the path to the folder will be relative to the project
|
|
468
|
+
* root. If `false`, it will be relative to where the application
|
|
469
|
+
* executable is located.
|
|
470
|
+
*/
|
|
304
471
|
_addStaticsFolder(route, folder = "", onHome = false) {
|
|
305
472
|
const location = onHome ? "home" : "app";
|
|
306
473
|
const staticRoute = route.replace(/^\/+/, "");
|
|
@@ -311,6 +478,16 @@ class Jimpex extends import_jimple.Jimple {
|
|
|
311
478
|
controller: true
|
|
312
479
|
});
|
|
313
480
|
}
|
|
481
|
+
/**
|
|
482
|
+
* This helper method validates the `path` options in order to register the `app`
|
|
483
|
+
* location in the `pathUtils` service. The `app` location should be the path to where
|
|
484
|
+
* the application executable is located, but due to how ESM works, we can't infer it
|
|
485
|
+
* from the `module` object, so we need either recieved as the `appPath` setting, or try
|
|
486
|
+
* to get it from the parent module.
|
|
487
|
+
*
|
|
488
|
+
* @throws If the method should use the path from the parent module, but can't find
|
|
489
|
+
* it.
|
|
490
|
+
*/
|
|
314
491
|
_configurePath() {
|
|
315
492
|
const pathUtils = this.get("pathUtils");
|
|
316
493
|
const {
|
|
@@ -340,6 +517,12 @@ class Jimpex extends import_jimple.Jimple {
|
|
|
340
517
|
);
|
|
341
518
|
}
|
|
342
519
|
}
|
|
520
|
+
/**
|
|
521
|
+
* Setups the configuration service. The new configuration service requires async calls
|
|
522
|
+
* in order to load the configuration files (as it uses `import` instead of `require`),
|
|
523
|
+
* so it can't be instantiated as the other services.
|
|
524
|
+
* This method is called just before starting the application.
|
|
525
|
+
*/
|
|
343
526
|
async _setupConfig() {
|
|
344
527
|
if (this._configReady)
|
|
345
528
|
return;
|
|
@@ -370,16 +553,46 @@ class Jimpex extends import_jimple.Jimple {
|
|
|
370
553
|
await config.loadFromEnv();
|
|
371
554
|
}
|
|
372
555
|
}
|
|
556
|
+
/**
|
|
557
|
+
* Processes the resources from the mount queue (added with {@link Jimpex.mount} and
|
|
558
|
+
* {@link Jimpex.use}), and adds them to the Express application.
|
|
559
|
+
*/
|
|
373
560
|
_mountResources() {
|
|
374
561
|
this._mountQueue.forEach((mount) => mount(this._express));
|
|
375
562
|
this._mountQueue.length = 0;
|
|
376
563
|
}
|
|
564
|
+
/**
|
|
565
|
+
* Emits an event using the `events` service.
|
|
566
|
+
*
|
|
567
|
+
* @param name The name of the event to emit.
|
|
568
|
+
* @param payload The event payload.
|
|
569
|
+
* @template EventName The literal name of the event, to type the event payload.
|
|
570
|
+
*/
|
|
377
571
|
_emitEvent(name, payload) {
|
|
378
572
|
this.eventsHub.emit(name, payload);
|
|
379
573
|
}
|
|
574
|
+
/**
|
|
575
|
+
* Sends a target object to a list of reducer events so they can modify or replace it.
|
|
576
|
+
*
|
|
577
|
+
* @param name The name of the event to use.
|
|
578
|
+
* @param target The object to reduce with the event.
|
|
579
|
+
* @param payload Extra context for the listeners.
|
|
580
|
+
*/
|
|
380
581
|
_reduceWithEvent(name, target, payload) {
|
|
381
582
|
return this.eventsHub.reduceSync(name, target, payload);
|
|
382
583
|
}
|
|
584
|
+
/**
|
|
585
|
+
* Loads the contents of a dictionary of credentials files that need to be used to
|
|
586
|
+
* configure HTTPS.
|
|
587
|
+
*
|
|
588
|
+
* @param credentialsInfo The dictionary where the keys are the type of credentials
|
|
589
|
+
* (`ca`, `cert`, `key`) and the values are the paths to the
|
|
590
|
+
* files.
|
|
591
|
+
* @param onHome If this is `true`, the path of the files will be relative
|
|
592
|
+
* to the project root. If it is `false`, it will be relative
|
|
593
|
+
* to where the application executable is located.
|
|
594
|
+
* @returns
|
|
595
|
+
*/
|
|
383
596
|
async _loadCredentials(credentialsInfo, onHome = true) {
|
|
384
597
|
const location = onHome ? "home" : "app";
|
|
385
598
|
const pathUtils = this.get("pathUtils");
|
|
@@ -403,6 +616,18 @@ class Jimpex extends import_jimple.Jimple {
|
|
|
403
616
|
return acc;
|
|
404
617
|
}, {});
|
|
405
618
|
}
|
|
619
|
+
/**
|
|
620
|
+
* Validates the configuration and chooses the server the application needs to use: If
|
|
621
|
+
* HTTP2 is enabled, it will use Spdy; if HTTPS is enabled but HTTP is not, it will use
|
|
622
|
+
* the native HTTPS server; otherwise, it will be just the Express instance.
|
|
623
|
+
*
|
|
624
|
+
* @returns {Server}
|
|
625
|
+
* @throws {Error} If HTTP2 is enabled but HTTPS is not.
|
|
626
|
+
* @throws {Error} If HTTPS is enabled but there's no `https.credentials` object.
|
|
627
|
+
* @throws {Error} If HTTPS is enabled and no creadentials are found.
|
|
628
|
+
* @access protected
|
|
629
|
+
* @ignore
|
|
630
|
+
*/
|
|
406
631
|
async _createServer() {
|
|
407
632
|
const [http2Config = {}, httpsConfig = {}] = this.getConfig(["http2", "https"], true);
|
|
408
633
|
if (!http2Config.enabled && !httpsConfig.enabled) {
|