@flancer32/teq-web 0.5.0 → 0.7.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 +17 -0
- package/ai/abstractions.md +2 -2
- package/ai/examples/minimal-server.md +1 -0
- package/ai/overview.md +2 -0
- package/ai/rules.md +3 -0
- package/package.json +2 -2
- package/src/Back/Api/Handler.mjs +1 -1
- package/src/Back/Config/Runtime/Tls.mjs +86 -0
- package/src/Back/Config/Runtime.mjs +111 -0
- package/src/Back/Dto/Info.mjs +3 -7
- package/src/Back/Dto/RequestContext.mjs +33 -0
- package/src/Back/Dto/Source.mjs +2 -6
- package/src/Back/Handler/Pre/Log.mjs +5 -9
- package/src/Back/Handler/Static/A/Config.mjs +3 -7
- package/src/Back/Handler/Static/A/Fallback.mjs +3 -7
- package/src/Back/Handler/Static/A/FileService.mjs +11 -15
- package/src/Back/Handler/Static/A/Registry.mjs +4 -8
- package/src/Back/Handler/Static/A/Resolver.mjs +3 -7
- package/src/Back/Handler/Static.mjs +8 -12
- package/src/Back/Helper/Respond.mjs +6 -10
- package/src/Back/PipelineEngine.mjs +27 -39
- package/src/Back/Server.mjs +17 -20
- package/types.d.ts +23 -5
- package/src/Back/Defaults.mjs +0 -11
- package/src/Back/Server/Config/Tls.mjs +0 -57
- package/src/Back/Server/Config.mjs +0 -69
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.7.0] - 2026-03-16 - Runtime composition and agent interface alignment
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
- Refined runtime configuration composition for server and TLS branches and preserved immutable runtime state semantics.
|
|
7
|
+
- Updated and verified the `ai/` consumer interface documentation against the current package behavior and usage rules.
|
|
8
|
+
- Updated package version metadata to `0.7.0`.
|
|
9
|
+
|
|
10
|
+
## [0.6.0] - 2026-03-16 - Runtime configuration hardening
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Added JSDoc coverage for request-context DTO usage and runtime configuration components.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- Refined runtime configuration composition for server and TLS settings.
|
|
17
|
+
- Hardened runtime configuration objects to remain immutable after initialization.
|
|
18
|
+
- Updated package version metadata to `0.6.0`.
|
|
19
|
+
|
|
3
20
|
## [0.5.0] - 2026-03-13
|
|
4
21
|
|
|
5
22
|
### Added
|
package/ai/abstractions.md
CHANGED
|
@@ -16,13 +16,13 @@ Main methods:
|
|
|
16
16
|
|
|
17
17
|
`Fl32_Web_Back_Server$` is the built-in transport adapter around Node.js `http` and `http2`. On `start(cfg)` it locks the pipeline, creates the server instance, binds request events to the Pipeline Engine, and starts listening.
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Default transport settings come from `Fl32_Web_Back_Config_Runtime$` under the `server` branch. TLS values for `server.tls` are provided by the dedicated runtime configuration component `Fl32_Web_Back_Config_Runtime_Tls$`. Supported transport modes come from `Fl32_Web_Back_Enum_Server_Type$`:
|
|
20
20
|
|
|
21
21
|
- `http`
|
|
22
22
|
- `http2`
|
|
23
23
|
- `https`
|
|
24
24
|
|
|
25
|
-
`https` requires
|
|
25
|
+
`https` requires `server.tls`.
|
|
26
26
|
|
|
27
27
|
## Handler Contract
|
|
28
28
|
|
|
@@ -74,5 +74,6 @@ Consumer notes:
|
|
|
74
74
|
- The composition root configures namespace roots once and resolves one application entry service.
|
|
75
75
|
- Application modules do not construct collaborators directly and do not call `new` for DI-managed handlers or infrastructure services.
|
|
76
76
|
- `server.start()` locks handler registration for the runtime lifetime of that server instance.
|
|
77
|
+
- Built-in server defaults may also be supplied through `Fl32_Web_Back_Config_Runtime__Factory$` as `{server: {port, type, tls}}`, where `tls` is owned by the runtime component `Fl32_Web_Back_Config_Runtime_Tls$`.
|
|
77
78
|
- If your application already has its own transport layer, inject `Fl32_Web_Back_PipelineEngine$` and call `pipeline.onEventRequest(req, res)` from that adapter instead of using `Fl32_Web_Back_Server$`.
|
|
78
79
|
- A correct PROCESS handler ends the response and then marks the context completed.
|
package/ai/overview.md
CHANGED
|
@@ -6,6 +6,8 @@ This package is not a general-purpose web framework. It does not define routing,
|
|
|
6
6
|
|
|
7
7
|
The package assumes `@teqfw/di` and exposes its runtime surface through DI-managed modules under the `Fl32_Web_` namespace rooted at the published `src/` tree. In normal usage, application modules receive these dependencies through constructor injection and orchestrate them from DI-managed services rather than creating containers or wiring collaborators manually inside feature code.
|
|
8
8
|
|
|
9
|
+
Runtime startup configuration is exposed through `Fl32_Web_Back_Config_Runtime$`. Its built-in transport branch is `config.server`, which contains `port`, `type`, and a `tls` branch backed by `Fl32_Web_Back_Config_Runtime_Tls$`.
|
|
10
|
+
|
|
9
11
|
Use this package when external code needs one of these roles:
|
|
10
12
|
|
|
11
13
|
- accept HTTP, HTTPS, or HTTP/2 requests with the built-in server;
|
package/ai/rules.md
CHANGED
|
@@ -38,4 +38,7 @@
|
|
|
38
38
|
|
|
39
39
|
- The package is designed for `@teqfw/di`.
|
|
40
40
|
- Consumer code should resolve package modules through the `Fl32_Web_` namespace mapped to the package `src/` path.
|
|
41
|
+
- Startup configuration for the built-in server should be supplied through `Fl32_Web_Back_Config_Runtime__Factory$` using the hierarchical configuration shape `{server: {...}}`.
|
|
42
|
+
- TLS startup configuration belongs to the dedicated runtime component `Fl32_Web_Back_Config_Runtime_Tls$`, even though consumers read it through `config.server.tls`.
|
|
43
|
+
- Configure runtime values during startup only; once the runtime configuration is frozen for use, consumers must treat `Fl32_Web_Back_Config_Runtime$` and `Fl32_Web_Back_Config_Runtime_Tls$` as immutable read-only state.
|
|
41
44
|
- Treat helper internals under deep implementation paths as non-essential unless the task specifically requires them. Preferred consumer entry points are the Pipeline Engine, Server, handler API, DTO factories, enums, and built-in handlers.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flancer32/teq-web",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Server-side web request coordination infrastructure for TeqFW modular monolith applications.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
]
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@teqfw/di": "^2.0
|
|
44
|
+
"@teqfw/di": "^2.1.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/node": "^25.4.0",
|
package/src/Back/Api/Handler.mjs
CHANGED
|
@@ -9,7 +9,7 @@ export default class Fl32_Web_Back_Api_Handler {
|
|
|
9
9
|
/* eslint-disable no-unused-vars */
|
|
10
10
|
/**
|
|
11
11
|
* Handles one request context in a pipeline stage.
|
|
12
|
-
* @param {
|
|
12
|
+
* @param {Fl32_Web_Back_Dto_RequestContext} context
|
|
13
13
|
* @returns {Promise<void>}
|
|
14
14
|
*/
|
|
15
15
|
async handle(context) {
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
export const __deps__ = Object.freeze({
|
|
4
|
+
cast: 'Fl32_Web_Back_Helper_Cast$',
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* TLS runtime configuration.
|
|
9
|
+
*/
|
|
10
|
+
export class Data {
|
|
11
|
+
/** @type {string|undefined} */
|
|
12
|
+
ca;
|
|
13
|
+
/** @type {string|undefined} */
|
|
14
|
+
cert;
|
|
15
|
+
/** @type {string|undefined} */
|
|
16
|
+
key;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** @type {Fl32_Web_Back_Config_Runtime_Tls} */
|
|
20
|
+
const cfg = new Data();
|
|
21
|
+
let frozen = false;
|
|
22
|
+
|
|
23
|
+
const facade = {};
|
|
24
|
+
|
|
25
|
+
/** @type {Fl32_Web_Back_Config_Runtime_Tls} */
|
|
26
|
+
const proxy = new Proxy(facade, {
|
|
27
|
+
get(_target, prop) {
|
|
28
|
+
const isServiceProp = (prop === 'then') || (typeof prop === 'symbol');
|
|
29
|
+
if (!frozen && !isServiceProp) throw new Error('Runtime configuration is not initialized.');
|
|
30
|
+
return cfg[prop];
|
|
31
|
+
},
|
|
32
|
+
set() {
|
|
33
|
+
throw new Error('Runtime configuration is immutable.');
|
|
34
|
+
},
|
|
35
|
+
defineProperty() {
|
|
36
|
+
throw new Error('Runtime configuration is immutable.');
|
|
37
|
+
},
|
|
38
|
+
deleteProperty() {
|
|
39
|
+
throw new Error('Runtime configuration is immutable.');
|
|
40
|
+
},
|
|
41
|
+
preventExtensions() {
|
|
42
|
+
throw new Error('Runtime configuration wrapper cannot be frozen.');
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export default class Wrapper {
|
|
47
|
+
constructor() {
|
|
48
|
+
return proxy;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export class Factory {
|
|
53
|
+
/**
|
|
54
|
+
* @param {object} params
|
|
55
|
+
* @param {Fl32_Web_Back_Helper_Cast} params.cast
|
|
56
|
+
*/
|
|
57
|
+
constructor({cast}) {
|
|
58
|
+
/**
|
|
59
|
+
* @param {Fl32_Web_Back_Config_Runtime_Tls_Params} [params]
|
|
60
|
+
* @returns {Fl32_Web_Back_Config_Runtime_Tls}
|
|
61
|
+
*/
|
|
62
|
+
this.configure = function (params = {}) {
|
|
63
|
+
if (frozen) throw new Error('Runtime configuration is frozen.');
|
|
64
|
+
if (cfg.ca === undefined && params.ca !== undefined) {
|
|
65
|
+
cfg.ca = cast.string(params.ca);
|
|
66
|
+
}
|
|
67
|
+
if (cfg.cert === undefined && params.cert !== undefined) {
|
|
68
|
+
cfg.cert = cast.string(params.cert);
|
|
69
|
+
}
|
|
70
|
+
if (cfg.key === undefined && params.key !== undefined) {
|
|
71
|
+
cfg.key = cast.string(params.key);
|
|
72
|
+
}
|
|
73
|
+
return proxy;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @returns {Fl32_Web_Back_Config_Runtime_Tls}
|
|
78
|
+
*/
|
|
79
|
+
this.freeze = function () {
|
|
80
|
+
if (frozen) return proxy;
|
|
81
|
+
Object.freeze(cfg);
|
|
82
|
+
frozen = true;
|
|
83
|
+
return proxy;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
export const __deps__ = Object.freeze({
|
|
4
|
+
cast: 'Fl32_Web_Back_Helper_Cast$',
|
|
5
|
+
SERVER_TYPE: 'Fl32_Web_Back_Enum_Server_Type$',
|
|
6
|
+
tlsFactory: 'Fl32_Web_Back_Config_Runtime_Tls__Factory$',
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Backend runtime configuration.
|
|
11
|
+
*/
|
|
12
|
+
export class Data {
|
|
13
|
+
/** @type {Fl32_Web_Back_Config_Runtime_Server|undefined} */
|
|
14
|
+
server;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Built-in server runtime configuration subtree.
|
|
19
|
+
*/
|
|
20
|
+
export class Server {
|
|
21
|
+
/** @type {number|undefined} */
|
|
22
|
+
port;
|
|
23
|
+
/** @type {string|undefined} */
|
|
24
|
+
type;
|
|
25
|
+
/** @type {Fl32_Web_Back_Config_Runtime_Tls|undefined} */
|
|
26
|
+
tls;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** @type {Fl32_Web_Back_Config_Runtime} */
|
|
30
|
+
const cfg = new Data();
|
|
31
|
+
let frozen = false;
|
|
32
|
+
|
|
33
|
+
const facade = {};
|
|
34
|
+
|
|
35
|
+
/** @type {Fl32_Web_Back_Config_Runtime} */
|
|
36
|
+
const proxy = new Proxy(facade, {
|
|
37
|
+
get(_target, prop) {
|
|
38
|
+
const isServiceProp = (prop === 'then') || (typeof prop === 'symbol');
|
|
39
|
+
if (!frozen && !isServiceProp) throw new Error('Runtime configuration is not initialized.');
|
|
40
|
+
return cfg[prop];
|
|
41
|
+
},
|
|
42
|
+
set() {
|
|
43
|
+
throw new Error('Runtime configuration is immutable.');
|
|
44
|
+
},
|
|
45
|
+
defineProperty() {
|
|
46
|
+
throw new Error('Runtime configuration is immutable.');
|
|
47
|
+
},
|
|
48
|
+
deleteProperty() {
|
|
49
|
+
throw new Error('Runtime configuration is immutable.');
|
|
50
|
+
},
|
|
51
|
+
preventExtensions() {
|
|
52
|
+
throw new Error('Runtime configuration wrapper cannot be frozen.');
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export default class Wrapper {
|
|
57
|
+
constructor() {
|
|
58
|
+
return proxy;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export class Factory {
|
|
63
|
+
/**
|
|
64
|
+
* @param {object} params
|
|
65
|
+
* @param {Fl32_Web_Back_Helper_Cast} params.cast
|
|
66
|
+
* @param {Fl32_Web_Back_Enum_Server_Type} params.SERVER_TYPE
|
|
67
|
+
* @param {Fl32_Web_Back_Config_Runtime_Tls$Factory} params.tlsFactory
|
|
68
|
+
*/
|
|
69
|
+
constructor({ cast, SERVER_TYPE, tlsFactory }) {
|
|
70
|
+
/**
|
|
71
|
+
* @param {Fl32_Web_Back_Config_Runtime_Params} [params]
|
|
72
|
+
* @returns {Fl32_Web_Back_Config_Runtime}
|
|
73
|
+
*/
|
|
74
|
+
this.configure = function (params = {}) {
|
|
75
|
+
if (frozen) throw new Error('Runtime configuration is frozen.');
|
|
76
|
+
if (cfg.server === undefined) cfg.server = new Server();
|
|
77
|
+
if (cfg.server.port === undefined && params.server?.port !== undefined) {
|
|
78
|
+
cfg.server.port = cast.int(params.server.port);
|
|
79
|
+
}
|
|
80
|
+
if (cfg.server.type === undefined && params.server?.type !== undefined) {
|
|
81
|
+
cfg.server.type = cast.enum(params.server.type, SERVER_TYPE, { lower: true });
|
|
82
|
+
}
|
|
83
|
+
if (params.server?.tls !== undefined) {
|
|
84
|
+
tlsFactory.configure(params.server.tls);
|
|
85
|
+
}
|
|
86
|
+
return proxy;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @returns {Fl32_Web_Back_Config_Runtime}
|
|
91
|
+
*/
|
|
92
|
+
this.freeze = function () {
|
|
93
|
+
if (frozen) return proxy;
|
|
94
|
+
if (cfg.server === undefined) cfg.server = new Server();
|
|
95
|
+
if (cfg.server.port === undefined) cfg.server.port = 3000;
|
|
96
|
+
if (cfg.server.type === undefined) cfg.server.type = SERVER_TYPE.HTTP;
|
|
97
|
+
const tls = tlsFactory.freeze();
|
|
98
|
+
if (cfg.server.tls === undefined) cfg.server.tls = tls;
|
|
99
|
+
if (cfg.server.type === SERVER_TYPE.HTTPS && cfg.server.tls === undefined) {
|
|
100
|
+
throw new Error('TLS configuration is required for HTTPS server type');
|
|
101
|
+
}
|
|
102
|
+
if (cfg.server.type === SERVER_TYPE.HTTPS && (!cfg.server.tls.key || !cfg.server.tls.cert)) {
|
|
103
|
+
throw new Error('TLS configuration is required for HTTPS server type');
|
|
104
|
+
}
|
|
105
|
+
Object.freeze(cfg.server);
|
|
106
|
+
Object.freeze(cfg);
|
|
107
|
+
frozen = true;
|
|
108
|
+
return proxy;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
package/src/Back/Dto/Info.mjs
CHANGED
|
@@ -5,12 +5,6 @@ export const __deps__ = Object.freeze({
|
|
|
5
5
|
STAGE: 'Fl32_Web_Back_Enum_Stage$',
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* @typedef {object} Fl32_Web_Back_Dto_InfoFactoryParams
|
|
10
|
-
* @property {Fl32_Web_Back_Helper_Cast} cast
|
|
11
|
-
* @property {Fl32_Web_Back_Enum_Stage} STAGE
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
8
|
export default class Fl32_Web_Back_Dto_Info {
|
|
15
9
|
/**
|
|
16
10
|
* Handlers to run before this one.
|
|
@@ -41,7 +35,9 @@ export default class Fl32_Web_Back_Dto_Info {
|
|
|
41
35
|
export class Factory {
|
|
42
36
|
/* eslint-disable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
43
37
|
/**
|
|
44
|
-
* @param {
|
|
38
|
+
* @param {object} params
|
|
39
|
+
* @param {Fl32_Web_Back_Helper_Cast} params.cast
|
|
40
|
+
* @param {Fl32_Web_Back_Enum_Stage} params.STAGE
|
|
45
41
|
*/
|
|
46
42
|
constructor(
|
|
47
43
|
{
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Request context passed through the pipeline lifecycle.
|
|
5
|
+
*/
|
|
6
|
+
export default class Fl32_Web_Back_Dto_RequestContext {
|
|
7
|
+
/** @type {Fl32_Web_Node_Http_IncomingMessage|Fl32_Web_Node_Http2_ServerRequest} */
|
|
8
|
+
request;
|
|
9
|
+
|
|
10
|
+
/** @type {Fl32_Web_Back_Response_Target} */
|
|
11
|
+
response;
|
|
12
|
+
|
|
13
|
+
/** @type {Record<string, unknown>} */
|
|
14
|
+
data = {};
|
|
15
|
+
|
|
16
|
+
/** @type {boolean} */
|
|
17
|
+
completed = false;
|
|
18
|
+
|
|
19
|
+
/** @type {() => void} */
|
|
20
|
+
complete;
|
|
21
|
+
|
|
22
|
+
/** @type {() => boolean} */
|
|
23
|
+
isCompleted;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class Factory {
|
|
27
|
+
/**
|
|
28
|
+
* @returns {Fl32_Web_Back_Dto_RequestContext}
|
|
29
|
+
*/
|
|
30
|
+
create() {
|
|
31
|
+
return new Fl32_Web_Back_Dto_RequestContext();
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/Back/Dto/Source.mjs
CHANGED
|
@@ -4,11 +4,6 @@ export const __deps__ = Object.freeze({
|
|
|
4
4
|
cast: 'Fl32_Web_Back_Helper_Cast$',
|
|
5
5
|
});
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* @typedef {object} Fl32_Web_Back_Dto_SourceFactoryParams
|
|
9
|
-
* @property {Fl32_Web_Back_Helper_Cast} cast
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
7
|
export default class Fl32_Web_Back_Dto_Source {
|
|
13
8
|
/** @type {string} */
|
|
14
9
|
root;
|
|
@@ -23,7 +18,8 @@ export default class Fl32_Web_Back_Dto_Source {
|
|
|
23
18
|
export class Factory {
|
|
24
19
|
/* eslint-disable jsdoc/require-param-description */
|
|
25
20
|
/**
|
|
26
|
-
* @param {
|
|
21
|
+
* @param {object} params
|
|
22
|
+
* @param {Fl32_Web_Back_Helper_Cast} params.cast
|
|
27
23
|
*/
|
|
28
24
|
constructor(
|
|
29
25
|
{
|
|
@@ -11,17 +11,13 @@ export const __deps__ = Object.freeze({
|
|
|
11
11
|
STAGE: 'Fl32_Web_Back_Enum_Stage$',
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* @typedef {object} Fl32_Web_Back_Handler_Pre_LogConstructorParams
|
|
16
|
-
* @property {Fl32_Web_Back_Logger} logger
|
|
17
|
-
* @property {Fl32_Web_Back_Dto_Info$Factory} dtoInfoFactory
|
|
18
|
-
* @property {Fl32_Web_Back_Enum_Stage} STAGE
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
14
|
export default class Fl32_Web_Back_Handler_Pre_Log {
|
|
22
15
|
/* eslint-disable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
23
16
|
/**
|
|
24
|
-
* @param {
|
|
17
|
+
* @param {object} params
|
|
18
|
+
* @param {Fl32_Web_Back_Logger} params.logger
|
|
19
|
+
* @param {Fl32_Web_Back_Dto_Info$Factory} params.dtoInfoFactory
|
|
20
|
+
* @param {Fl32_Web_Back_Enum_Stage} params.STAGE
|
|
25
21
|
*/
|
|
26
22
|
constructor(
|
|
27
23
|
{
|
|
@@ -42,7 +38,7 @@ export default class Fl32_Web_Back_Handler_Pre_Log {
|
|
|
42
38
|
/**
|
|
43
39
|
* Log request method and URL.
|
|
44
40
|
*
|
|
45
|
-
* @param {
|
|
41
|
+
* @param {Fl32_Web_Back_Dto_RequestContext} context
|
|
46
42
|
* @returns {Promise<void>}
|
|
47
43
|
*/
|
|
48
44
|
this.handle = async function (context) {
|
|
@@ -4,16 +4,12 @@ export const __deps__ = Object.freeze({
|
|
|
4
4
|
path: 'node_path',
|
|
5
5
|
});
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* @typedef {object} Fl32_Web_Back_Handler_Static_A_ConfigConstructorParams
|
|
9
|
-
* @property {typeof import('node:path')} path
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
7
|
export default class Fl32_Web_Back_Handler_Static_A_Config {
|
|
13
8
|
static DEFAULT_FILES = ['index.html', 'index.htm', 'index.txt'];
|
|
14
9
|
/* eslint-disable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
15
10
|
/**
|
|
16
|
-
* @param {
|
|
11
|
+
* @param {object} params
|
|
12
|
+
* @param {Fl32_Web_Node_Path} params.path
|
|
17
13
|
*/
|
|
18
14
|
constructor(
|
|
19
15
|
{
|
|
@@ -26,7 +22,7 @@ export default class Fl32_Web_Back_Handler_Static_A_Config {
|
|
|
26
22
|
* Normalize DTO fields into configuration object.
|
|
27
23
|
*
|
|
28
24
|
* @param {Fl32_Web_Back_Dto_Source} dto
|
|
29
|
-
* @returns {
|
|
25
|
+
* @returns {Fl32_Web_Back_Handler_Static_A_Config_Value}
|
|
30
26
|
* @throws {Error} When required fields are missing or invalid.
|
|
31
27
|
*/
|
|
32
28
|
this.create = (dto) => {
|
|
@@ -5,16 +5,12 @@ export const __deps__ = Object.freeze({
|
|
|
5
5
|
path: 'node_path',
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* @typedef {object} Fl32_Web_Back_Handler_Static_A_FallbackConstructorParams
|
|
10
|
-
* @property {typeof import('node:fs')} fs
|
|
11
|
-
* @property {typeof import('node:path')} path
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
8
|
export default class Fl32_Web_Back_Handler_Static_A_Fallback {
|
|
15
9
|
/* eslint-disable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
16
10
|
/**
|
|
17
|
-
* @param {
|
|
11
|
+
* @param {object} params
|
|
12
|
+
* @param {Fl32_Web_Node_Fs} params.fs
|
|
13
|
+
* @param {Fl32_Web_Node_Path} params.path
|
|
18
14
|
*/
|
|
19
15
|
constructor(
|
|
20
16
|
{
|
|
@@ -10,21 +10,17 @@ export const __deps__ = Object.freeze({
|
|
|
10
10
|
fallback: 'Fl32_Web_Back_Handler_Static_A_Fallback$',
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
/**
|
|
14
|
-
* @typedef {object} Fl32_Web_Back_Handler_Static_A_FileServiceConstructorParams
|
|
15
|
-
* @property {typeof import('node:fs')} fs
|
|
16
|
-
* @property {typeof import('node:http2')} http2
|
|
17
|
-
* @property {typeof import('node:path')} path
|
|
18
|
-
* @property {Fl32_Web_Back_Logger} logger
|
|
19
|
-
* @property {Fl32_Web_Back_Helper_Mime} helpMime
|
|
20
|
-
* @property {Fl32_Web_Back_Handler_Static_A_Resolver} resolver
|
|
21
|
-
* @property {Fl32_Web_Back_Handler_Static_A_Fallback} fallback
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
13
|
export default class Fl32_Web_Back_Handler_Static_A_FileService {
|
|
25
14
|
/* eslint-disable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
26
15
|
/**
|
|
27
|
-
* @param {
|
|
16
|
+
* @param {object} params
|
|
17
|
+
* @param {Fl32_Web_Node_Fs} params.fs
|
|
18
|
+
* @param {Fl32_Web_Node_Http2} params.http2
|
|
19
|
+
* @param {Fl32_Web_Node_Path} params.path
|
|
20
|
+
* @param {Fl32_Web_Back_Logger} params.logger
|
|
21
|
+
* @param {Fl32_Web_Back_Helper_Mime} params.helpMime
|
|
22
|
+
* @param {Fl32_Web_Back_Handler_Static_A_Resolver} params.resolver
|
|
23
|
+
* @param {Fl32_Web_Back_Handler_Static_A_Fallback} params.fallback
|
|
28
24
|
*/
|
|
29
25
|
constructor(
|
|
30
26
|
{
|
|
@@ -43,10 +39,10 @@ export default class Fl32_Web_Back_Handler_Static_A_FileService {
|
|
|
43
39
|
/**
|
|
44
40
|
* Serve a file for given config and relative path.
|
|
45
41
|
*
|
|
46
|
-
* @param {
|
|
42
|
+
* @param {Fl32_Web_Back_Handler_Static_A_Config_Value} config
|
|
47
43
|
* @param {string} rel
|
|
48
|
-
* @param {
|
|
49
|
-
* @param {
|
|
44
|
+
* @param {Fl32_Web_Node_Http_IncomingMessage|Fl32_Web_Node_Http2_ServerRequest} req
|
|
45
|
+
* @param {Fl32_Web_Back_Response_Target} res
|
|
50
46
|
* @returns {Promise<boolean>} true if served
|
|
51
47
|
*/
|
|
52
48
|
this.serve = async (config, rel, req, res) => {
|
|
@@ -5,16 +5,12 @@ export const __deps__ = Object.freeze({
|
|
|
5
5
|
logger: 'Fl32_Web_Back_Logger$',
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* @typedef {object} Fl32_Web_Back_Handler_Static_A_RegistryConstructorParams
|
|
10
|
-
* @property {Fl32_Web_Back_Handler_Static_A_Config} configFactory
|
|
11
|
-
* @property {Fl32_Web_Back_Logger} logger
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
8
|
export default class Fl32_Web_Back_Handler_Static_A_Registry {
|
|
15
9
|
/* eslint-disable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
16
10
|
/**
|
|
17
|
-
* @param {
|
|
11
|
+
* @param {object} params
|
|
12
|
+
* @param {Fl32_Web_Back_Handler_Static_A_Config} params.configFactory
|
|
13
|
+
* @param {Fl32_Web_Back_Logger} params.logger
|
|
18
14
|
*/
|
|
19
15
|
constructor(
|
|
20
16
|
{
|
|
@@ -49,7 +45,7 @@ export default class Fl32_Web_Back_Handler_Static_A_Registry {
|
|
|
49
45
|
* Find configuration by matching URL prefix.
|
|
50
46
|
*
|
|
51
47
|
* @param {string} url
|
|
52
|
-
* @returns {
|
|
48
|
+
* @returns {Fl32_Web_Back_Handler_Static_A_Match|null}
|
|
53
49
|
*/
|
|
54
50
|
this.find = function (url) {
|
|
55
51
|
for (const cfg of _configs) {
|
|
@@ -8,21 +8,17 @@ export const __deps__ = Object.freeze({
|
|
|
8
8
|
path: 'node_path',
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* @typedef {object} Fl32_Web_Back_Handler_Static_A_ResolverConstructorParams
|
|
13
|
-
* @property {typeof import('node:path')} path
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
11
|
export default class Fl32_Web_Back_Handler_Static_A_Resolver {
|
|
17
12
|
/**
|
|
18
|
-
* @param {
|
|
13
|
+
* @param {object} params
|
|
14
|
+
* @param {Fl32_Web_Node_Path} params.path
|
|
19
15
|
*/
|
|
20
16
|
constructor({path}) {
|
|
21
17
|
/**
|
|
22
18
|
* Resolve a filesystem path for given config and relative URL part.
|
|
23
19
|
* Applies allow rules and prevents path traversal.
|
|
24
20
|
*
|
|
25
|
-
* @param {
|
|
21
|
+
* @param {Fl32_Web_Back_Handler_Static_A_Config_Value} config
|
|
26
22
|
* @param {string} rel
|
|
27
23
|
* @returns {string|null}
|
|
28
24
|
* @throws {Error} On traversal or absolute rel paths.
|
|
@@ -14,20 +14,16 @@ export const __deps__ = Object.freeze({
|
|
|
14
14
|
STAGE: 'Fl32_Web_Back_Enum_Stage$',
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* @typedef {object} Fl32_Web_Back_Handler_StaticConstructorParams
|
|
19
|
-
* @property {Fl32_Web_Back_Handler_Static_A_Registry} registry
|
|
20
|
-
* @property {Fl32_Web_Back_Handler_Static_A_FileService} fileService
|
|
21
|
-
* @property {Fl32_Web_Back_Helper_Respond} respond
|
|
22
|
-
* @property {Fl32_Web_Back_Logger} logger
|
|
23
|
-
* @property {Fl32_Web_Back_Dto_Info$Factory} dtoInfoFactory
|
|
24
|
-
* @property {Fl32_Web_Back_Enum_Stage} STAGE
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
17
|
export default class Fl32_Web_Back_Handler_Static {
|
|
28
18
|
/* eslint-disable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
29
19
|
/**
|
|
30
|
-
* @param {
|
|
20
|
+
* @param {object} params
|
|
21
|
+
* @param {Fl32_Web_Back_Handler_Static_A_Registry} params.registry
|
|
22
|
+
* @param {Fl32_Web_Back_Handler_Static_A_FileService} params.fileService
|
|
23
|
+
* @param {Fl32_Web_Back_Helper_Respond} params.respond
|
|
24
|
+
* @param {Fl32_Web_Back_Logger} params.logger
|
|
25
|
+
* @param {Fl32_Web_Back_Dto_Info$Factory} params.dtoInfoFactory
|
|
26
|
+
* @param {Fl32_Web_Back_Enum_Stage} params.STAGE
|
|
31
27
|
*/
|
|
32
28
|
constructor(
|
|
33
29
|
{
|
|
@@ -59,7 +55,7 @@ export default class Fl32_Web_Back_Handler_Static {
|
|
|
59
55
|
/**
|
|
60
56
|
* Attempt to handle incoming request.
|
|
61
57
|
*
|
|
62
|
-
* @param {
|
|
58
|
+
* @param {Fl32_Web_Back_Dto_RequestContext} context
|
|
63
59
|
* @returns {Promise<void>}
|
|
64
60
|
*/
|
|
65
61
|
this.handle = async (context) => {
|
|
@@ -5,14 +5,10 @@ export const __deps__ = Object.freeze({
|
|
|
5
5
|
http2: 'node_http2',
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* @typedef {object} Fl32_Web_Back_Helper_RespondConstructorParams
|
|
10
|
-
* @property {typeof import('node:http2')} http2
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
8
|
export default class Fl32_Web_Back_Helper_Respond {
|
|
14
9
|
/**
|
|
15
|
-
* @param {
|
|
10
|
+
* @param {object} params
|
|
11
|
+
* @param {Fl32_Web_Node_Http2} params.http2
|
|
16
12
|
*/
|
|
17
13
|
constructor(
|
|
18
14
|
{
|
|
@@ -47,9 +43,9 @@ export default class Fl32_Web_Back_Helper_Respond {
|
|
|
47
43
|
* Sends an HTTP response with a given status code.
|
|
48
44
|
*
|
|
49
45
|
* @param {object} params
|
|
50
|
-
* @param {
|
|
51
|
-
* @param {
|
|
52
|
-
* @param {
|
|
46
|
+
* @param {Fl32_Web_Back_Response_Target} params.res - HTTP response object.
|
|
47
|
+
* @param {Fl32_Web_Back_Response_Headers} [params.headers={}] - Custom headers.
|
|
48
|
+
* @param {Fl32_Web_Back_Response_Body} [params.body=''] - Response body.
|
|
53
49
|
* @param {number} status - HTTP status code.
|
|
54
50
|
* @returns {boolean} - `true` if response was sent, `false` if headers were already sent.
|
|
55
51
|
*/
|
|
@@ -156,7 +152,7 @@ export default class Fl32_Web_Back_Helper_Respond {
|
|
|
156
152
|
|
|
157
153
|
/**
|
|
158
154
|
* Checks if the response is writable and not yet sent.
|
|
159
|
-
* @param {
|
|
155
|
+
* @param {Fl32_Web_Back_Response_Target} res
|
|
160
156
|
* @returns {boolean}
|
|
161
157
|
*/
|
|
162
158
|
this.isWritable = function (res) {
|
|
@@ -6,39 +6,28 @@
|
|
|
6
6
|
* `INIT -> PROCESS -> FINALIZE`.
|
|
7
7
|
*/
|
|
8
8
|
export const __deps__ = Object.freeze({
|
|
9
|
+
dtoRequestContextFactory: 'Fl32_Web_Back_Dto_RequestContext__Factory$',
|
|
9
10
|
logger: 'Fl32_Web_Back_Logger$',
|
|
10
11
|
respond: 'Fl32_Web_Back_Helper_Respond$',
|
|
11
12
|
helpOrder: 'Fl32_Web_Back_Helper_Order_Kahn$',
|
|
12
13
|
STAGE: 'Fl32_Web_Back_Enum_Stage$',
|
|
13
14
|
});
|
|
14
15
|
|
|
15
|
-
/**
|
|
16
|
-
* @typedef {object} Fl32_Web_Back_PipelineEngineConstructorParams
|
|
17
|
-
* @property {Fl32_Web_Back_Logger} logger
|
|
18
|
-
* @property {Fl32_Web_Back_Helper_Respond} respond
|
|
19
|
-
* @property {Fl32_Web_Back_Helper_Order_Kahn} helpOrder
|
|
20
|
-
* @property {Fl32_Web_Back_Enum_Stage} STAGE
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @typedef {object} Fl32_Web_Back_PipelineEngine_RequestContext
|
|
25
|
-
* @property {module:http.IncomingMessage|module:http2.Http2ServerRequest} request
|
|
26
|
-
* @property {module:http.ServerResponse|module:http2.Http2ServerResponse} response
|
|
27
|
-
* @property {Record<string, unknown>} data
|
|
28
|
-
* @property {boolean} completed
|
|
29
|
-
* @property {() => void} complete
|
|
30
|
-
* @property {() => boolean} isCompleted
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
16
|
const KEY_STAGE = Symbol('stage');
|
|
34
17
|
|
|
35
18
|
export default class Fl32_Web_Back_PipelineEngine {
|
|
36
19
|
/* eslint-disable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
37
20
|
/**
|
|
38
|
-
* @param {
|
|
21
|
+
* @param {object} params
|
|
22
|
+
* @param {Fl32_Web_Back_Dto_RequestContext$Factory} params.dtoRequestContextFactory
|
|
23
|
+
* @param {Fl32_Web_Back_Logger} params.logger
|
|
24
|
+
* @param {Fl32_Web_Back_Helper_Respond} params.respond
|
|
25
|
+
* @param {Fl32_Web_Back_Helper_Order_Kahn} params.helpOrder
|
|
26
|
+
* @param {Fl32_Web_Back_Enum_Stage} params.STAGE
|
|
39
27
|
*/
|
|
40
28
|
constructor(
|
|
41
29
|
{
|
|
30
|
+
dtoRequestContextFactory,
|
|
42
31
|
logger,
|
|
43
32
|
respond,
|
|
44
33
|
helpOrder,
|
|
@@ -57,24 +46,23 @@ export default class Fl32_Web_Back_PipelineEngine {
|
|
|
57
46
|
let isLocked = false;
|
|
58
47
|
|
|
59
48
|
/**
|
|
60
|
-
* @param {
|
|
61
|
-
* @param {
|
|
62
|
-
* @returns {
|
|
49
|
+
* @param {Fl32_Web_Node_Http_IncomingMessage|Fl32_Web_Node_Http2_ServerRequest} request
|
|
50
|
+
* @param {Fl32_Web_Back_Response_Target} response
|
|
51
|
+
* @returns {Fl32_Web_Back_Dto_RequestContext}
|
|
63
52
|
*/
|
|
64
53
|
function createRequestContext(request, response) {
|
|
65
54
|
let completed = false;
|
|
66
|
-
/** @type {
|
|
67
|
-
const context =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
},
|
|
75
|
-
isCompleted: () => completed,
|
|
76
|
-
[KEY_STAGE]: null,
|
|
55
|
+
/** @type {Fl32_Web_Back_Dto_RequestContext & {[KEY_STAGE]: string|null}} */
|
|
56
|
+
const context = dtoRequestContextFactory.create();
|
|
57
|
+
context.request = request;
|
|
58
|
+
context.response = response;
|
|
59
|
+
context.data = {};
|
|
60
|
+
context.completed = false;
|
|
61
|
+
context.complete = () => {
|
|
62
|
+
context.completed = true;
|
|
77
63
|
};
|
|
64
|
+
context.isCompleted = () => completed;
|
|
65
|
+
context[KEY_STAGE] = null;
|
|
78
66
|
|
|
79
67
|
Object.defineProperty(context, 'completed', {
|
|
80
68
|
configurable: false,
|
|
@@ -104,7 +92,7 @@ export default class Fl32_Web_Back_PipelineEngine {
|
|
|
104
92
|
/**
|
|
105
93
|
* @param {Fl32_Web_Back_Api_Handler} handler
|
|
106
94
|
* @param {string} stage
|
|
107
|
-
* @param {
|
|
95
|
+
* @param {Fl32_Web_Back_Dto_RequestContext & {[KEY_STAGE]: string|null}} context
|
|
108
96
|
* @returns {Promise<void>}
|
|
109
97
|
*/
|
|
110
98
|
async function runHandler(handler, stage, context) {
|
|
@@ -166,15 +154,15 @@ export default class Fl32_Web_Back_PipelineEngine {
|
|
|
166
154
|
this.registerHandler = (handler) => this.addHandler(handler);
|
|
167
155
|
|
|
168
156
|
/**
|
|
169
|
-
* @param {
|
|
170
|
-
* @param {
|
|
157
|
+
* @param {Fl32_Web_Node_Http_IncomingMessage|Fl32_Web_Node_Http2_ServerRequest} req
|
|
158
|
+
* @param {Fl32_Web_Back_Response_Target} res
|
|
171
159
|
* @returns {Promise<void>}
|
|
172
160
|
*/
|
|
173
161
|
this.onEventRequest = async function (req, res) {
|
|
174
162
|
if (!isLocked) {
|
|
175
163
|
this.orderHandlers();
|
|
176
164
|
}
|
|
177
|
-
/** @type {
|
|
165
|
+
/** @type {Fl32_Web_Back_Dto_RequestContext & {[KEY_STAGE]: string|null}} */
|
|
178
166
|
const context = createRequestContext(req, res);
|
|
179
167
|
|
|
180
168
|
try {
|
|
@@ -219,8 +207,8 @@ export default class Fl32_Web_Back_PipelineEngine {
|
|
|
219
207
|
};
|
|
220
208
|
|
|
221
209
|
/**
|
|
222
|
-
* @param {
|
|
223
|
-
* @param {
|
|
210
|
+
* @param {Fl32_Web_Node_Http_IncomingMessage|Fl32_Web_Node_Http2_ServerRequest} req
|
|
211
|
+
* @param {Fl32_Web_Back_Response_Target} res
|
|
224
212
|
* @returns {Promise<void>}
|
|
225
213
|
*/
|
|
226
214
|
this.handleRequest = async (req, res) => this.onEventRequest(req, res);
|
package/src/Back/Server.mjs
CHANGED
|
@@ -7,32 +7,28 @@
|
|
|
7
7
|
export const __deps__ = Object.freeze({
|
|
8
8
|
http: 'node_http',
|
|
9
9
|
http2: 'node_http2',
|
|
10
|
-
|
|
10
|
+
config: 'Fl32_Web_Back_Config_Runtime$',
|
|
11
11
|
logger: 'Fl32_Web_Back_Logger$',
|
|
12
12
|
pipelineEngine: 'Fl32_Web_Back_PipelineEngine$',
|
|
13
13
|
SERVER_TYPE: 'Fl32_Web_Back_Enum_Server_Type$',
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* @typedef {object} Fl32_Web_Back_ServerConstructorParams
|
|
18
|
-
* @property {typeof import('node:http')} http
|
|
19
|
-
* @property {typeof import('node:http2')} http2
|
|
20
|
-
* @property {import('./Defaults.mjs').default} DEF
|
|
21
|
-
* @property {Fl32_Web_Back_Logger} logger
|
|
22
|
-
* @property {Fl32_Web_Back_PipelineEngine} pipelineEngine
|
|
23
|
-
* @property {Fl32_Web_Back_Enum_Server_Type} SERVER_TYPE
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
16
|
export default class Fl32_Web_Back_Server {
|
|
27
17
|
/* eslint-disable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
28
18
|
/**
|
|
29
|
-
* @param {
|
|
19
|
+
* @param {object} deps
|
|
20
|
+
* @param {Fl32_Web_Node_Http} deps.http
|
|
21
|
+
* @param {Fl32_Web_Node_Http2} deps.http2
|
|
22
|
+
* @param {Fl32_Web_Back_Config_Runtime} deps.config
|
|
23
|
+
* @param {Fl32_Web_Back_Logger} deps.logger
|
|
24
|
+
* @param {Fl32_Web_Back_PipelineEngine} deps.pipelineEngine
|
|
25
|
+
* @param {Fl32_Web_Back_Enum_Server_Type} deps.SERVER_TYPE
|
|
30
26
|
*/
|
|
31
27
|
constructor(
|
|
32
28
|
{
|
|
33
29
|
http,
|
|
34
30
|
http2,
|
|
35
|
-
|
|
31
|
+
config,
|
|
36
32
|
logger,
|
|
37
33
|
pipelineEngine,
|
|
38
34
|
SERVER_TYPE,
|
|
@@ -42,25 +38,26 @@ export default class Fl32_Web_Back_Server {
|
|
|
42
38
|
// VARS
|
|
43
39
|
const { createServer } = http;
|
|
44
40
|
const { createServer: createServerH2, createSecureServer } = http2;
|
|
45
|
-
/** @type {
|
|
41
|
+
/** @type {Fl32_Web_Node_Http_Server} */
|
|
46
42
|
let _instance;
|
|
47
43
|
|
|
48
44
|
// MAIN
|
|
49
45
|
/**
|
|
50
|
-
* @returns {
|
|
46
|
+
* @returns {Fl32_Web_Node_Http_Server}
|
|
51
47
|
*/
|
|
52
48
|
this.getInstance = () => _instance;
|
|
53
49
|
|
|
54
50
|
/**
|
|
55
51
|
* Starts the server with optional configuration.
|
|
56
|
-
* @param {
|
|
52
|
+
* @param {Fl32_Web_Back_Config_Runtime_Server} [cfg]
|
|
57
53
|
* @returns {Promise<void>}
|
|
58
54
|
*/
|
|
59
55
|
this.start = async function (cfg) {
|
|
60
56
|
pipelineEngine.lockHandlers();
|
|
61
57
|
// create server
|
|
62
|
-
const port = cfg?.port ??
|
|
63
|
-
const type = cfg?.type ??
|
|
58
|
+
const port = cfg?.port ?? config.server.port;
|
|
59
|
+
const type = cfg?.type ?? config.server.type;
|
|
60
|
+
const tls = cfg?.tls ?? config.server.tls;
|
|
64
61
|
|
|
65
62
|
if (type === SERVER_TYPE.HTTP2) {
|
|
66
63
|
_instance = createServerH2();
|
|
@@ -69,11 +66,11 @@ export default class Fl32_Web_Back_Server {
|
|
|
69
66
|
_instance = createServer({});
|
|
70
67
|
logger.info(`Starting server in HTTP/1 mode on port ${port}...`);
|
|
71
68
|
} else if (type === SERVER_TYPE.HTTPS) {
|
|
72
|
-
if (!
|
|
69
|
+
if (!tls?.key || !tls?.cert) {
|
|
73
70
|
logger.error('HTTPS server requires TLS key and certificate');
|
|
74
71
|
throw new Error('TLS key and certificate are required for HTTPS server');
|
|
75
72
|
}
|
|
76
|
-
_instance = createSecureServer(
|
|
73
|
+
_instance = createSecureServer(tls);
|
|
77
74
|
logger.info(`Starting server in HTTPS (HTTP/2 + TLS) mode on port ${port}...`);
|
|
78
75
|
} else {
|
|
79
76
|
logger.error(`Unsupported server type: ${type}`);
|
package/types.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
declare global {
|
|
2
2
|
type Fl32_Web_Back_Api_Handler = import("./src/Back/Api/Handler.mjs").default;
|
|
3
|
-
type
|
|
3
|
+
type Fl32_Web_Back_Config_Runtime = import("./src/Back/Config/Runtime.mjs").Data;
|
|
4
|
+
type Fl32_Web_Back_Config_Runtime$Factory = import("./src/Back/Config/Runtime.mjs").Factory;
|
|
5
|
+
type Fl32_Web_Back_Config_Runtime_Server = import("./src/Back/Config/Runtime.mjs").Server;
|
|
6
|
+
type Fl32_Web_Back_Config_Runtime_Tls = import("./src/Back/Config/Runtime/Tls.mjs").Data;
|
|
7
|
+
type Fl32_Web_Back_Config_Runtime_Tls$Factory = import("./src/Back/Config/Runtime/Tls.mjs").Factory;
|
|
8
|
+
type Fl32_Web_Back_Config_Runtime_Params = {server?: {port?: unknown, type?: unknown, tls?: unknown}};
|
|
9
|
+
type Fl32_Web_Back_Config_Runtime_Tls_Params = {ca?: unknown, cert?: unknown, key?: unknown};
|
|
4
10
|
type Fl32_Web_Back_Dto_Info = import("./src/Back/Dto/Info.mjs").default;
|
|
5
11
|
type Fl32_Web_Back_Dto_Info$Factory = import("./src/Back/Dto/Info.mjs").Factory;
|
|
12
|
+
type Fl32_Web_Back_Dto_RequestContext = import("./src/Back/Dto/RequestContext.mjs").default;
|
|
13
|
+
type Fl32_Web_Back_Dto_RequestContext$Factory = import("./src/Back/Dto/RequestContext.mjs").Factory;
|
|
6
14
|
type Fl32_Web_Back_Dto_Source = import("./src/Back/Dto/Source.mjs").default;
|
|
7
15
|
type Fl32_Web_Back_Dto_Source$Factory = import("./src/Back/Dto/Source.mjs").Factory;
|
|
8
16
|
type Fl32_Web_Back_Enum_Server_Type = import("./src/Back/Enum/Server/Type.mjs").default;
|
|
@@ -10,8 +18,10 @@ declare global {
|
|
|
10
18
|
type Fl32_Web_Back_Handler_Pre_Log = import("./src/Back/Handler/Pre/Log.mjs").default;
|
|
11
19
|
type Fl32_Web_Back_Handler_Static = import("./src/Back/Handler/Static.mjs").default;
|
|
12
20
|
type Fl32_Web_Back_Handler_Static_A_Config = import("./src/Back/Handler/Static/A/Config.mjs").default;
|
|
21
|
+
type Fl32_Web_Back_Handler_Static_A_Config_Value = {root: string, prefix: string, allow?: Record<string, string[]>, defaults: string[]};
|
|
13
22
|
type Fl32_Web_Back_Handler_Static_A_Fallback = import("./src/Back/Handler/Static/A/Fallback.mjs").default;
|
|
14
23
|
type Fl32_Web_Back_Handler_Static_A_FileService = import("./src/Back/Handler/Static/A/FileService.mjs").default;
|
|
24
|
+
type Fl32_Web_Back_Handler_Static_A_Match = {config: Fl32_Web_Back_Handler_Static_A_Config_Value, rel: string};
|
|
15
25
|
type Fl32_Web_Back_Handler_Static_A_Registry = import("./src/Back/Handler/Static/A/Registry.mjs").default;
|
|
16
26
|
type Fl32_Web_Back_Handler_Static_A_Resolver = import("./src/Back/Handler/Static/A/Resolver.mjs").default;
|
|
17
27
|
type Fl32_Web_Back_Helper_Cast = import("./src/Back/Helper/Cast.mjs").default;
|
|
@@ -20,11 +30,19 @@ declare global {
|
|
|
20
30
|
type Fl32_Web_Back_Helper_Respond = import("./src/Back/Helper/Respond.mjs").default;
|
|
21
31
|
type Fl32_Web_Back_Logger = import("./src/Back/Logger.mjs").default;
|
|
22
32
|
type Fl32_Web_Back_PipelineEngine = import("./src/Back/PipelineEngine.mjs").default;
|
|
33
|
+
type Fl32_Web_Back_Response_Body = string | object;
|
|
34
|
+
type Fl32_Web_Back_Response_Headers = {[key: string]: string};
|
|
35
|
+
type Fl32_Web_Back_Response_Target = Fl32_Web_Node_Http_ServerResponse | Fl32_Web_Node_Http2_ServerResponse;
|
|
23
36
|
type Fl32_Web_Back_Server = import("./src/Back/Server.mjs").default;
|
|
24
|
-
type
|
|
25
|
-
type
|
|
26
|
-
type
|
|
27
|
-
type
|
|
37
|
+
type Fl32_Web_Node_Fs = typeof import("node:fs");
|
|
38
|
+
type Fl32_Web_Node_Http = typeof import("node:http");
|
|
39
|
+
type Fl32_Web_Node_Http_Server = import("node:http").Server;
|
|
40
|
+
type Fl32_Web_Node_Http_IncomingMessage = import("node:http").IncomingMessage;
|
|
41
|
+
type Fl32_Web_Node_Http_ServerResponse = import("node:http").ServerResponse;
|
|
42
|
+
type Fl32_Web_Node_Http2 = typeof import("node:http2");
|
|
43
|
+
type Fl32_Web_Node_Http2_ServerRequest = import("node:http2").Http2ServerRequest;
|
|
44
|
+
type Fl32_Web_Node_Http2_ServerResponse = import("node:http2").Http2ServerResponse;
|
|
45
|
+
type Fl32_Web_Node_Path = typeof import("node:path");
|
|
28
46
|
}
|
|
29
47
|
|
|
30
48
|
export {};
|
package/src/Back/Defaults.mjs
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
export const __deps__ = Object.freeze({
|
|
4
|
-
cast: 'Fl32_Web_Back_Helper_Cast$',
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @typedef {object} Fl32_Web_Back_Server_Config_TlsFactoryParams
|
|
9
|
-
* @property {Fl32_Web_Back_Helper_Cast} cast
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
export default class Fl32_Web_Back_Server_Config_Tls {
|
|
13
|
-
/**
|
|
14
|
-
* Trusted CA certificates in PEM format.
|
|
15
|
-
* @type {string|undefined}
|
|
16
|
-
*/
|
|
17
|
-
ca;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Certificate in PEM format.
|
|
21
|
-
* @type {string}
|
|
22
|
-
*/
|
|
23
|
-
cert;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Private key in PEM format.
|
|
27
|
-
* @type {string}
|
|
28
|
-
*/
|
|
29
|
-
key;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export class Factory {
|
|
33
|
-
/* eslint-disable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
34
|
-
/**
|
|
35
|
-
* @param {Fl32_Web_Back_Server_Config_TlsFactoryParams} params
|
|
36
|
-
*/
|
|
37
|
-
constructor(
|
|
38
|
-
{
|
|
39
|
-
cast,
|
|
40
|
-
}
|
|
41
|
-
) {
|
|
42
|
-
/* eslint-enable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
43
|
-
/**
|
|
44
|
-
* @param {*} [data]
|
|
45
|
-
* @returns {Fl32_Web_Back_Server_Config_Tls}
|
|
46
|
-
*/
|
|
47
|
-
this.create = function (data) {
|
|
48
|
-
const res = new Fl32_Web_Back_Server_Config_Tls();
|
|
49
|
-
if (data) {
|
|
50
|
-
res.ca = cast.string(data?.ca);
|
|
51
|
-
res.cert = cast.string(data.cert);
|
|
52
|
-
res.key = cast.string(data.key);
|
|
53
|
-
}
|
|
54
|
-
return Object.freeze(res);
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
export const __deps__ = Object.freeze({
|
|
4
|
-
cast: 'Fl32_Web_Back_Helper_Cast$',
|
|
5
|
-
SERVER_TYPE: 'Fl32_Web_Back_Enum_Server_Type$',
|
|
6
|
-
tlsFactory: 'Fl32_Web_Back_Server_Config_Tls__Factory$',
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @typedef {object} Fl32_Web_Back_Server_ConfigFactoryParams
|
|
11
|
-
* @property {Fl32_Web_Back_Helper_Cast} cast
|
|
12
|
-
* @property {Fl32_Web_Back_Enum_Server_Type} SERVER_TYPE
|
|
13
|
-
* @property {Fl32_Web_Back_Server_Config_Tls$Factory} tlsFactory
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
export default class Fl32_Web_Back_Server_Config {
|
|
17
|
-
/**
|
|
18
|
-
* Port to listening (3000).
|
|
19
|
-
*
|
|
20
|
-
* @type {number}
|
|
21
|
-
*/
|
|
22
|
-
port;
|
|
23
|
-
/**
|
|
24
|
-
* @type {string}
|
|
25
|
-
* @see Fl32_Web_Back_Enum_Server_Type
|
|
26
|
-
*/
|
|
27
|
-
type;
|
|
28
|
-
/**
|
|
29
|
-
* TLS configuration for HTTPS server.
|
|
30
|
-
* @type {Fl32_Web_Back_Server_Config_Tls|undefined}
|
|
31
|
-
*/
|
|
32
|
-
tls;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export class Factory {
|
|
36
|
-
/* eslint-disable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
37
|
-
/**
|
|
38
|
-
* @param {Fl32_Web_Back_Server_ConfigFactoryParams} params
|
|
39
|
-
*/
|
|
40
|
-
constructor(
|
|
41
|
-
{
|
|
42
|
-
cast,
|
|
43
|
-
SERVER_TYPE,
|
|
44
|
-
tlsFactory,
|
|
45
|
-
}
|
|
46
|
-
) {
|
|
47
|
-
/* eslint-enable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
48
|
-
/**
|
|
49
|
-
* @param {Fl32_Web_Back_Server_Config|object} [data]
|
|
50
|
-
* @returns {Fl32_Web_Back_Server_Config}
|
|
51
|
-
*/
|
|
52
|
-
this.create = function (data) {
|
|
53
|
-
const res = new Fl32_Web_Back_Server_Config();
|
|
54
|
-
if (data) {
|
|
55
|
-
res.port = cast.int(data.port);
|
|
56
|
-
res.type = cast.enum(data.type, SERVER_TYPE, {lower: true});
|
|
57
|
-
|
|
58
|
-
if (data.tls) {
|
|
59
|
-
res.tls = tlsFactory.create(data.tls);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (res.type === SERVER_TYPE.HTTPS && !res.tls) {
|
|
63
|
-
throw new Error('TLS configuration is required for HTTPS server type');
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return Object.freeze(res);
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
}
|