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