@rsdk/http.server 5.0.0-next.1 → 5.0.0-next.3
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 +14 -0
- package/dist/http.headers.d.ts +6 -11
- package/dist/http.headers.js +5 -13
- package/dist/http.headers.js.map +1 -1
- package/dist/http.transport.d.ts +30 -14
- package/dist/http.transport.js +54 -70
- package/dist/http.transport.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/service-routes.js +2 -2
- package/dist/service-routes.js.map +1 -1
- package/package.json +2 -3
- package/src/http.headers.ts +12 -34
- package/src/http.transport.ts +75 -92
- package/src/index.ts +1 -1
- package/dist/http-adapter/abstract-rsdk-http-adapter.d.ts +0 -28
- package/dist/http-adapter/abstract-rsdk-http-adapter.js +0 -96
- package/dist/http-adapter/abstract-rsdk-http-adapter.js.map +0 -1
- package/dist/http.tracing-extractor.d.ts +0 -6
- package/dist/http.tracing-extractor.js +0 -13
- package/dist/http.tracing-extractor.js.map +0 -1
- package/src/http-adapter/abstract-rsdk-http-adapter.ts +0 -158
- package/src/http.tracing-extractor.ts +0 -16
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [5.0.0-next.3](https://github.com/R-Vision/rsdk/compare/v5.0.0-next.2...v5.0.0-next.3) (2024-07-11)
|
|
7
|
+
|
|
8
|
+
### ⚠ BREAKING CHANGES
|
|
9
|
+
|
|
10
|
+
* generalize tracing headers (#247)
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* generalize tracing headers ([#247](https://github.com/R-Vision/rsdk/issues/247)) ([cee2ea6](https://github.com/R-Vision/rsdk/commit/cee2ea65c964705faf133397e285c051672c7512)), closes [#2](https://github.com/R-Vision/rsdk/issues/2) [#3](https://github.com/R-Vision/rsdk/issues/3) [#4](https://github.com/R-Vision/rsdk/issues/4) [#5](https://github.com/R-Vision/rsdk/issues/5)
|
|
15
|
+
|
|
16
|
+
## [5.0.0-next.2](https://github.com/R-Vision/rsdk/compare/v5.0.0-next.1...v5.0.0-next.2) (2024-07-10)
|
|
17
|
+
|
|
18
|
+
**Note:** Version bump only for package @rsdk/http.server
|
|
19
|
+
|
|
6
20
|
## [5.0.0-next.1](https://github.com/R-Vision/rsdk/compare/v5.0.0-next.0...v5.0.0-next.1) (2024-07-10)
|
|
7
21
|
|
|
8
22
|
**Note:** Version bump only for package @rsdk/http.server
|
package/dist/http.headers.d.ts
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { ArgumentsHost } from '@nestjs/common';
|
|
2
|
+
import type { GenericHeaders } from '@rsdk/core';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Обёртка над http-заголовками.
|
|
5
5
|
*/
|
|
6
|
-
export declare class HttpHeaders {
|
|
7
|
-
constructor(headers: Record<string, string>);
|
|
8
|
-
get<K extends string>(key: MaybeReadonlyArray<K>): Record<K, string | undefined>;
|
|
9
|
-
get(key: string): string | undefined;
|
|
10
|
-
getTracingHeaders(): TracingHeaders;
|
|
11
|
-
getHeaders(): {
|
|
12
|
-
'x-requestid'?: string;
|
|
13
|
-
};
|
|
6
|
+
export declare class HttpHeaders implements GenericHeaders {
|
|
14
7
|
private normalizedHeaders;
|
|
8
|
+
constructor(ctx: ArgumentsHost);
|
|
9
|
+
get(key: string): string | undefined;
|
|
15
10
|
}
|
package/dist/http.headers.js
CHANGED
|
@@ -1,27 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HttpHeaders = void 0;
|
|
4
|
-
const types_1 = require("@rsdk/core/dist/tracing/types");
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
5
|
+
* Обёртка над http-заголовками.
|
|
7
6
|
*/
|
|
8
7
|
class HttpHeaders {
|
|
9
|
-
|
|
8
|
+
normalizedHeaders;
|
|
9
|
+
constructor(ctx) {
|
|
10
|
+
const req = ctx.switchToHttp().getRequest();
|
|
11
|
+
const headers = req.headers;
|
|
10
12
|
this.normalizedHeaders = Object.fromEntries(Object.entries(headers).map(([k, v]) => [k.toLowerCase(), v]));
|
|
11
13
|
}
|
|
12
14
|
get(key) {
|
|
13
|
-
if (Array.isArray(key)) {
|
|
14
|
-
return Object.fromEntries(key.map((k) => [k, this.get(k)]));
|
|
15
|
-
}
|
|
16
15
|
return this.normalizedHeaders[key.toLowerCase()];
|
|
17
16
|
}
|
|
18
|
-
getTracingHeaders() {
|
|
19
|
-
return new types_1.TracingHeaders(this.getHeaders());
|
|
20
|
-
}
|
|
21
|
-
getHeaders() {
|
|
22
|
-
return this.get(types_1.tracingHeaders);
|
|
23
|
-
}
|
|
24
|
-
normalizedHeaders;
|
|
25
17
|
}
|
|
26
18
|
exports.HttpHeaders = HttpHeaders;
|
|
27
19
|
//# sourceMappingURL=http.headers.js.map
|
package/dist/http.headers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.headers.js","sourceRoot":"","sources":["../src/http.headers.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"http.headers.js","sourceRoot":"","sources":["../src/http.headers.ts"],"names":[],"mappings":";;;AAGA;;GAEG;AACH,MAAa,WAAW;IACd,iBAAiB,CAAyB;IAElD,YAAY,GAAkB;QAC5B,MAAM,GAAG,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAO,CAAC;QACjD,MAAM,OAAO,GAAG,GAAG,CAAC,OAAiC,CAAC;QAEtD,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC,WAAW,CACzC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,CAC9D,CAAC;IACJ,CAAC;IAED,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;IACnD,CAAC;CACF;AAfD,kCAeC"}
|
package/dist/http.transport.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ExecutionContext } from '@nestjs/common';
|
|
2
2
|
import type { Controller, INestApplication } from '@nestjs/common/interfaces';
|
|
3
3
|
import type { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
|
|
4
|
-
import type
|
|
4
|
+
import { type AbstractHttpAdapter } from '@nestjs/core';
|
|
5
5
|
import { DocumentBuilder as OriginalDocumentBuilder } from '@nestjs/swagger';
|
|
6
6
|
import type { Constructor, DeepPartial } from '@rsdk/common';
|
|
7
|
-
import type { ConfigContext, HttpOptions, IErrorsFormatter, IErrorsSender, IErrorsTransformer, IHttpTransport,
|
|
7
|
+
import type { ConfigContext, GenericHeaders, HttpOptions, IErrorsFormatter, IErrorsSender, IErrorsTransformer, IHttpTransport, NestModuleDefinitions } from '@rsdk/core';
|
|
8
|
+
import { HttpConfig } from './http.config';
|
|
8
9
|
export interface ParsersConfig {
|
|
9
10
|
body: {
|
|
10
11
|
json: boolean;
|
|
@@ -19,27 +20,42 @@ export interface SwaggerOptions {
|
|
|
19
20
|
configure(builder: DocumentBuilder): void;
|
|
20
21
|
}
|
|
21
22
|
export interface HttpTransportOptions {
|
|
23
|
+
/**
|
|
24
|
+
* CORS middleware options
|
|
25
|
+
*/
|
|
22
26
|
cors?: CorsOptions;
|
|
27
|
+
/**
|
|
28
|
+
* Global prefix (will be used in app.setGlobalPrefix())
|
|
29
|
+
*/
|
|
23
30
|
globalPrefix?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Configuration of body and cookie parsers
|
|
33
|
+
// NOTE: This fields is actually is handled in transport specific way
|
|
34
|
+
*/
|
|
24
35
|
parsers?: DeepPartial<ParsersConfig>;
|
|
36
|
+
/**
|
|
37
|
+
* Swagger options. You can configure OpenAPI document
|
|
38
|
+
* builder or set file to write on application start
|
|
39
|
+
*
|
|
40
|
+
* NOTE: SwaggerUI is enabled or disabled by HTTP_SWAGGER_UI_ENABLED
|
|
41
|
+
* (true by default).
|
|
42
|
+
*/
|
|
25
43
|
swagger?: DeepPartial<SwaggerOptions>;
|
|
26
44
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
private readonly adapter;
|
|
32
|
-
private readonly options;
|
|
33
|
-
getHeaderExtractor(): ProtocolTracingHeadersExtractor;
|
|
34
|
-
constructor(adapter: AbstractHttpAdapter, options?: HttpTransportOptions);
|
|
45
|
+
export declare abstract class AbstractHttpTransport implements IHttpTransport {
|
|
46
|
+
protected readonly options?: HttpTransportOptions | undefined;
|
|
47
|
+
constructor(options?: HttpTransportOptions | undefined);
|
|
48
|
+
extractHeaders(ctx: ExecutionContext): GenericHeaders;
|
|
35
49
|
matchByContext(ctx: ExecutionContext): boolean;
|
|
36
|
-
|
|
37
|
-
createAdapter(): AbstractHttpAdapter;
|
|
50
|
+
modules(): NestModuleDefinitions;
|
|
38
51
|
getErrorsFormatter(): IErrorsFormatter;
|
|
39
52
|
getErrorsSender(): IErrorsSender;
|
|
40
53
|
getErrorTransformers(): IErrorsTransformer[];
|
|
41
|
-
|
|
54
|
+
getProtocol(): string;
|
|
42
55
|
getHealthController(): Constructor<Controller>;
|
|
43
56
|
getMetricsController(): Constructor<Controller>;
|
|
44
57
|
createHttpOptions(configContext: ConfigContext): HttpOptions;
|
|
58
|
+
createAdapter(configContext: ConfigContext): AbstractHttpAdapter;
|
|
59
|
+
configureApp(app: INestApplication, configContext: ConfigContext): Promise<void> | void;
|
|
60
|
+
abstract createHttpAdapter(httpConfig: HttpConfig): AbstractHttpAdapter;
|
|
45
61
|
}
|
package/dist/http.transport.js
CHANGED
|
@@ -1,40 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const
|
|
3
|
+
exports.AbstractHttpTransport = void 0;
|
|
4
|
+
const core_1 = require("@nestjs/core");
|
|
8
5
|
const swagger_1 = require("@nestjs/swagger");
|
|
9
|
-
const
|
|
10
|
-
const body_parser_1 = require("body-parser");
|
|
11
|
-
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
6
|
+
const core_2 = require("@rsdk/core");
|
|
12
7
|
const node_fs_1 = require("node:fs");
|
|
13
8
|
const controllers_1 = require("./controllers");
|
|
14
9
|
const error_handling_1 = require("./error-handling");
|
|
15
10
|
const http_config_1 = require("./http.config");
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*/
|
|
20
|
-
class HttpTransport {
|
|
21
|
-
adapter;
|
|
11
|
+
const http_headers_1 = require("./http.headers");
|
|
12
|
+
const http_logger_interceptor_1 = require("./http-logger.interceptor");
|
|
13
|
+
class AbstractHttpTransport {
|
|
22
14
|
options;
|
|
23
|
-
|
|
24
|
-
return new http_tracing_extractor_1.HttpTracingExtractor();
|
|
25
|
-
}
|
|
26
|
-
constructor(adapter, options = {}) {
|
|
27
|
-
this.adapter = adapter;
|
|
15
|
+
constructor(options) {
|
|
28
16
|
this.options = options;
|
|
29
17
|
}
|
|
18
|
+
extractHeaders(ctx) {
|
|
19
|
+
return new http_headers_1.HttpHeaders(ctx);
|
|
20
|
+
}
|
|
30
21
|
matchByContext(ctx) {
|
|
31
22
|
return ctx.getType() === 'http';
|
|
32
23
|
}
|
|
33
|
-
|
|
34
|
-
return
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
modules() {
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
/**
|
|
28
|
+
* Abstract class is transpiled into a simple class just as not abstract classes.
|
|
29
|
+
* But typescript doesn't like this (((
|
|
30
|
+
*/
|
|
31
|
+
module: AbstractHttpTransport,
|
|
32
|
+
providers: [
|
|
33
|
+
{
|
|
34
|
+
provide: core_1.APP_INTERCEPTOR,
|
|
35
|
+
useClass: http_logger_interceptor_1.HttpLoggerInterceptor,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
];
|
|
38
40
|
}
|
|
39
41
|
getErrorsFormatter() {
|
|
40
42
|
return new error_handling_1.HttpErrorsFormatter();
|
|
@@ -45,47 +47,39 @@ class HttpTransport {
|
|
|
45
47
|
getErrorTransformers() {
|
|
46
48
|
return [new error_handling_1.HttpErrorsTransformer()];
|
|
47
49
|
}
|
|
50
|
+
getProtocol() {
|
|
51
|
+
return 'http';
|
|
52
|
+
}
|
|
53
|
+
getHealthController() {
|
|
54
|
+
return controllers_1.HealthHttpController;
|
|
55
|
+
}
|
|
56
|
+
getMetricsController() {
|
|
57
|
+
return controllers_1.MetricsHttpController;
|
|
58
|
+
}
|
|
59
|
+
createHttpOptions(configContext) {
|
|
60
|
+
const { host, port } = configContext.resolve(http_config_1.HttpConfig);
|
|
61
|
+
return {
|
|
62
|
+
host,
|
|
63
|
+
port,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
createAdapter(configContext) {
|
|
67
|
+
return this.createHttpAdapter(configContext.resolve(http_config_1.HttpConfig));
|
|
68
|
+
}
|
|
48
69
|
configureApp(app, configContext) {
|
|
49
|
-
const {
|
|
50
|
-
const {
|
|
51
|
-
if (cors) {
|
|
52
|
-
app.enableCors(cors);
|
|
53
|
-
}
|
|
70
|
+
const { swaggerUI } = configContext.resolve(http_config_1.HttpConfig);
|
|
71
|
+
const { globalPrefix, swagger, cors } = this.options ?? {};
|
|
54
72
|
if (globalPrefix) {
|
|
55
|
-
app.setGlobalPrefix(globalPrefix
|
|
56
|
-
exclude: [
|
|
57
|
-
{ method: common_1.RequestMethod.GET, path: '/metrics' },
|
|
58
|
-
{ method: common_1.RequestMethod.GET, path: '/health' },
|
|
59
|
-
],
|
|
60
|
-
});
|
|
73
|
+
app.setGlobalPrefix(globalPrefix);
|
|
61
74
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// express and fastify. Otherwise we will always have to deal
|
|
65
|
-
// with such leaky abstractions
|
|
66
|
-
if (this.adapter.constructor.name == 'ExpressAdapter') {
|
|
67
|
-
const { body, cookie } = Object.assign({
|
|
68
|
-
body: {
|
|
69
|
-
json: true,
|
|
70
|
-
urlencoded: false,
|
|
71
|
-
},
|
|
72
|
-
cookie: false,
|
|
73
|
-
}, parsers);
|
|
74
|
-
if (body.json) {
|
|
75
|
-
app.use((0, body_parser_1.json)({ limit: bodyLimit.bytes() }));
|
|
76
|
-
}
|
|
77
|
-
if (body.urlencoded) {
|
|
78
|
-
app.use((0, body_parser_1.urlencoded)({ extended: true, limit: bodyLimit.bytes() }));
|
|
79
|
-
}
|
|
80
|
-
if (cookie) {
|
|
81
|
-
app.use((0, cookie_parser_1.default)());
|
|
82
|
-
}
|
|
75
|
+
if (cors) {
|
|
76
|
+
app.enableCors(cors);
|
|
83
77
|
}
|
|
84
78
|
if (swaggerUI || swagger?.file) {
|
|
85
79
|
const builder = new swagger_1.DocumentBuilder()
|
|
86
|
-
.setTitle(app.get(
|
|
87
|
-
.setVersion(app.get(
|
|
88
|
-
.setDescription(app.get(
|
|
80
|
+
.setTitle(app.get(core_2.APP_NAME))
|
|
81
|
+
.setVersion(app.get(core_2.APP_VERSION))
|
|
82
|
+
.setDescription(app.get(core_2.APP_DESCRIPTION));
|
|
89
83
|
// Applies additional configuration from user
|
|
90
84
|
swagger?.configure?.(builder);
|
|
91
85
|
const openApiConfig = builder.build();
|
|
@@ -98,16 +92,6 @@ class HttpTransport {
|
|
|
98
92
|
}
|
|
99
93
|
}
|
|
100
94
|
}
|
|
101
|
-
getHealthController() {
|
|
102
|
-
return controllers_1.HealthHttpController;
|
|
103
|
-
}
|
|
104
|
-
getMetricsController() {
|
|
105
|
-
return controllers_1.MetricsHttpController;
|
|
106
|
-
}
|
|
107
|
-
createHttpOptions(configContext) {
|
|
108
|
-
const { host, port } = configContext.resolve(http_config_1.HttpConfig);
|
|
109
|
-
return { host, port };
|
|
110
|
-
}
|
|
111
95
|
}
|
|
112
|
-
exports.
|
|
96
|
+
exports.AbstractHttpTransport = AbstractHttpTransport;
|
|
113
97
|
//# sourceMappingURL=http.transport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.transport.js","sourceRoot":"","sources":["../src/http.transport.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http.transport.js","sourceRoot":"","sources":["../src/http.transport.ts"],"names":[],"mappings":"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"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,9 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.HttpHeaders = exports.
|
|
18
|
-
var
|
|
19
|
-
Object.defineProperty(exports, "
|
|
17
|
+
exports.HttpHeaders = exports.AbstractHttpTransport = void 0;
|
|
18
|
+
var http_transport_1 = require("./http.transport");
|
|
19
|
+
Object.defineProperty(exports, "AbstractHttpTransport", { enumerable: true, get: function () { return http_transport_1.AbstractHttpTransport; } });
|
|
20
20
|
__exportStar(require("./http.transport"), exports);
|
|
21
21
|
var http_headers_1 = require("./http.headers");
|
|
22
22
|
Object.defineProperty(exports, "HttpHeaders", { enumerable: true, get: function () { return http_headers_1.HttpHeaders; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mDAAyD;AAAhD,uHAAA,qBAAqB,OAAA;AAE9B,mDAAiC;AACjC,+CAA6C;AAApC,2GAAA,WAAW,OAAA"}
|
package/dist/service-routes.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ServiceRoutes = void 0;
|
|
4
|
+
exports.ServiceRoute = ServiceRoute;
|
|
4
5
|
const swagger_1 = require("@nestjs/swagger");
|
|
5
6
|
/**
|
|
6
7
|
* Хранение ссылок на обработчики http ручек.
|
|
@@ -19,5 +20,4 @@ function ServiceRoute() {
|
|
|
19
20
|
return (0, swagger_1.ApiExcludeEndpoint)(true)(target, propertyKey, descriptor);
|
|
20
21
|
};
|
|
21
22
|
}
|
|
22
|
-
exports.ServiceRoute = ServiceRoute;
|
|
23
23
|
//# sourceMappingURL=service-routes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-routes.js","sourceRoot":"","sources":["../src/service-routes.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"service-routes.js","sourceRoot":"","sources":["../src/service-routes.ts"],"names":[],"mappings":";;;AAiBA,oCAKC;AAtBD,6CAAqD;AAErD;;;GAGG;AACH,MAAa,aAAa;IACxB,MAAM,CAAC,OAAO,GAIR,EAAE,CAAC;;AALX,sCAMC;AAED;;GAEG;AACH,SAAgB,YAAY;IAC1B,OAAO,CAAC,MAAW,EAAE,WAAW,EAAE,UAAU,EAAE,EAAE;QAC9C,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC,CAAC;QAChE,OAAO,IAAA,4BAAkB,EAAC,IAAI,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;IACnE,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/http.server",
|
|
3
|
-
"version": "5.0.0-next.
|
|
3
|
+
"version": "5.0.0-next.3",
|
|
4
4
|
"description": "HTTP transport for rsdk apps (needs some of HTTP adapters)",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"@nestjs/common": "^10.0.0",
|
|
15
15
|
"@nestjs/core": "^10.0.0",
|
|
16
16
|
"@nestjs/swagger": "^7.0.0",
|
|
17
|
-
"@opentelemetry/semantic-conventions": "1.18.1",
|
|
18
17
|
"@rsdk/common": "*",
|
|
19
18
|
"@rsdk/core": "*",
|
|
20
19
|
"@rsdk/logging": "*",
|
|
@@ -23,5 +22,5 @@
|
|
|
23
22
|
"reflect-metadata": "^0.1.12 || ^0.2.0",
|
|
24
23
|
"rxjs": "^7.8.1"
|
|
25
24
|
},
|
|
26
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "c75ce1d8983ba69a6f855ba19536d28be0a9c519"
|
|
27
26
|
}
|
package/src/http.headers.ts
CHANGED
|
@@ -1,44 +1,22 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
type Headers,
|
|
4
|
-
TracingHeaders,
|
|
5
|
-
tracingHeaders,
|
|
6
|
-
} from '@rsdk/core/dist/tracing/types';
|
|
1
|
+
import type { ArgumentsHost } from '@nestjs/common';
|
|
2
|
+
import type { GenericHeaders } from '@rsdk/core';
|
|
7
3
|
|
|
8
4
|
/**
|
|
9
|
-
*
|
|
5
|
+
* Обёртка над http-заголовками.
|
|
10
6
|
*/
|
|
11
|
-
export class HttpHeaders {
|
|
12
|
-
|
|
7
|
+
export class HttpHeaders implements GenericHeaders {
|
|
8
|
+
private normalizedHeaders: Record<string, string>;
|
|
9
|
+
|
|
10
|
+
constructor(ctx: ArgumentsHost) {
|
|
11
|
+
const req = ctx.switchToHttp().getRequest<any>();
|
|
12
|
+
const headers = req.headers as Record<string, string>;
|
|
13
|
+
|
|
13
14
|
this.normalizedHeaders = Object.fromEntries(
|
|
14
15
|
Object.entries(headers).map(([k, v]) => [k.toLowerCase(), v]),
|
|
15
16
|
);
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
get
|
|
19
|
-
key
|
|
20
|
-
): Record<K, string | undefined>;
|
|
21
|
-
|
|
22
|
-
get(key: string): string | undefined;
|
|
23
|
-
|
|
24
|
-
get(
|
|
25
|
-
key: string | MaybeReadonlyArray<string>,
|
|
26
|
-
): Record<string, string | undefined> | string | undefined {
|
|
27
|
-
if (Array.isArray(key)) {
|
|
28
|
-
return Object.fromEntries(key.map((k) => [k, this.get(k)]));
|
|
29
|
-
}
|
|
30
|
-
return this.normalizedHeaders[(key as string).toLowerCase()];
|
|
19
|
+
get(key: string): string | undefined {
|
|
20
|
+
return this.normalizedHeaders[key.toLowerCase()];
|
|
31
21
|
}
|
|
32
|
-
|
|
33
|
-
getTracingHeaders(): TracingHeaders {
|
|
34
|
-
return new TracingHeaders(this.getHeaders());
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
getHeaders(): {
|
|
38
|
-
'x-requestid'?: string;
|
|
39
|
-
} {
|
|
40
|
-
return this.get(tracingHeaders) as Partial<Headers>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
private normalizedHeaders: Record<string, string>;
|
|
44
22
|
}
|
package/src/http.transport.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { RequestMethod } from '@nestjs/common';
|
|
1
|
+
import { type ExecutionContext } from '@nestjs/common';
|
|
3
2
|
import type { Controller, INestApplication } from '@nestjs/common/interfaces';
|
|
4
3
|
import type { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
|
|
5
|
-
import type
|
|
4
|
+
import { type AbstractHttpAdapter, APP_INTERCEPTOR } from '@nestjs/core';
|
|
6
5
|
import {
|
|
7
6
|
DocumentBuilder as OriginalDocumentBuilder,
|
|
8
7
|
SwaggerModule,
|
|
@@ -10,16 +9,15 @@ import {
|
|
|
10
9
|
import type { Constructor, DeepPartial } from '@rsdk/common';
|
|
11
10
|
import type {
|
|
12
11
|
ConfigContext,
|
|
12
|
+
GenericHeaders,
|
|
13
13
|
HttpOptions,
|
|
14
14
|
IErrorsFormatter,
|
|
15
15
|
IErrorsSender,
|
|
16
16
|
IErrorsTransformer,
|
|
17
17
|
IHttpTransport,
|
|
18
|
-
|
|
18
|
+
NestModuleDefinitions,
|
|
19
19
|
} from '@rsdk/core';
|
|
20
20
|
import { APP_DESCRIPTION, APP_NAME, APP_VERSION } from '@rsdk/core';
|
|
21
|
-
import { json, urlencoded } from 'body-parser';
|
|
22
|
-
import cookieParser from 'cookie-parser';
|
|
23
21
|
import { writeFileSync } from 'node:fs';
|
|
24
22
|
|
|
25
23
|
import { HealthHttpController, MetricsHttpController } from './controllers';
|
|
@@ -29,7 +27,8 @@ import {
|
|
|
29
27
|
HttpErrorsTransformer,
|
|
30
28
|
} from './error-handling';
|
|
31
29
|
import { HttpConfig } from './http.config';
|
|
32
|
-
import {
|
|
30
|
+
import { HttpHeaders } from './http.headers';
|
|
31
|
+
import { HttpLoggerInterceptor } from './http-logger.interceptor';
|
|
33
32
|
|
|
34
33
|
export interface ParsersConfig {
|
|
35
34
|
body: {
|
|
@@ -52,52 +51,59 @@ export interface SwaggerOptions {
|
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
export interface HttpTransportOptions {
|
|
55
|
-
|
|
54
|
+
/**
|
|
55
|
+
* CORS middleware options
|
|
56
|
+
*/
|
|
56
57
|
cors?: CorsOptions;
|
|
57
58
|
|
|
58
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Global prefix (will be used in app.setGlobalPrefix())
|
|
61
|
+
*/
|
|
59
62
|
globalPrefix?: string;
|
|
60
63
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
//
|
|
64
|
+
/**
|
|
65
|
+
* Configuration of body and cookie parsers
|
|
66
|
+
// NOTE: This fields is actually is handled in transport specific way
|
|
67
|
+
*/
|
|
64
68
|
parsers?: DeepPartial<ParsersConfig>;
|
|
65
69
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// running the app. Unfortunately there is no way to do it in Nest.js 9.
|
|
74
|
-
// Planned in https://jira.rvision.pro/browse/PFM-134
|
|
70
|
+
/**
|
|
71
|
+
* Swagger options. You can configure OpenAPI document
|
|
72
|
+
* builder or set file to write on application start
|
|
73
|
+
*
|
|
74
|
+
* NOTE: SwaggerUI is enabled or disabled by HTTP_SWAGGER_UI_ENABLED
|
|
75
|
+
* (true by default).
|
|
76
|
+
*/
|
|
75
77
|
swagger?: DeepPartial<SwaggerOptions>;
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
*/
|
|
81
|
-
export class HttpTransport implements IHttpTransport {
|
|
82
|
-
getHeaderExtractor(): ProtocolTracingHeadersExtractor {
|
|
83
|
-
return new HttpTracingExtractor();
|
|
84
|
-
}
|
|
80
|
+
export abstract class AbstractHttpTransport implements IHttpTransport {
|
|
81
|
+
constructor(protected readonly options?: HttpTransportOptions) {}
|
|
85
82
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
) {}
|
|
83
|
+
extractHeaders(ctx: ExecutionContext): GenericHeaders {
|
|
84
|
+
return new HttpHeaders(ctx);
|
|
85
|
+
}
|
|
90
86
|
|
|
91
87
|
matchByContext(ctx: ExecutionContext): boolean {
|
|
92
88
|
return ctx.getType() === 'http';
|
|
93
89
|
}
|
|
94
90
|
|
|
95
|
-
|
|
96
|
-
return
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
91
|
+
modules(): NestModuleDefinitions {
|
|
92
|
+
return [
|
|
93
|
+
{
|
|
94
|
+
/**
|
|
95
|
+
* Abstract class is transpiled into a simple class just as not abstract classes.
|
|
96
|
+
* But typescript doesn't like this (((
|
|
97
|
+
*/
|
|
98
|
+
module: AbstractHttpTransport as any,
|
|
99
|
+
providers: [
|
|
100
|
+
{
|
|
101
|
+
provide: APP_INTERCEPTOR,
|
|
102
|
+
useClass: HttpLoggerInterceptor,
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
];
|
|
101
107
|
}
|
|
102
108
|
|
|
103
109
|
getErrorsFormatter(): IErrorsFormatter {
|
|
@@ -112,53 +118,42 @@ export class HttpTransport implements IHttpTransport {
|
|
|
112
118
|
return [new HttpErrorsTransformer()];
|
|
113
119
|
}
|
|
114
120
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
): void | Promise<void> {
|
|
119
|
-
const { bodyLimit, swaggerUI } = configContext.resolve(HttpConfig);
|
|
120
|
-
const { cors, globalPrefix, parsers, swagger } = this.options;
|
|
121
|
+
getProtocol(): string {
|
|
122
|
+
return 'http';
|
|
123
|
+
}
|
|
121
124
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
+
getHealthController(): Constructor<Controller> {
|
|
126
|
+
return HealthHttpController;
|
|
127
|
+
}
|
|
125
128
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
{ method: RequestMethod.GET, path: '/metrics' },
|
|
130
|
-
{ method: RequestMethod.GET, path: '/health' },
|
|
131
|
-
],
|
|
132
|
-
});
|
|
133
|
-
}
|
|
129
|
+
getMetricsController(): Constructor<Controller> {
|
|
130
|
+
return MetricsHttpController;
|
|
131
|
+
}
|
|
134
132
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
// express and fastify. Otherwise we will always have to deal
|
|
138
|
-
// with such leaky abstractions
|
|
139
|
-
if (this.adapter.constructor.name == 'ExpressAdapter') {
|
|
140
|
-
const { body, cookie }: ParsersConfig = Object.assign(
|
|
141
|
-
{
|
|
142
|
-
body: {
|
|
143
|
-
json: true,
|
|
144
|
-
urlencoded: false,
|
|
145
|
-
},
|
|
146
|
-
cookie: false,
|
|
147
|
-
},
|
|
148
|
-
parsers,
|
|
149
|
-
);
|
|
133
|
+
createHttpOptions(configContext: ConfigContext): HttpOptions {
|
|
134
|
+
const { host, port } = configContext.resolve(HttpConfig);
|
|
150
135
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
136
|
+
return {
|
|
137
|
+
host,
|
|
138
|
+
port,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
154
141
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
142
|
+
createAdapter(configContext: ConfigContext): AbstractHttpAdapter {
|
|
143
|
+
return this.createHttpAdapter(configContext.resolve(HttpConfig));
|
|
144
|
+
}
|
|
158
145
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
146
|
+
configureApp(
|
|
147
|
+
app: INestApplication,
|
|
148
|
+
configContext: ConfigContext,
|
|
149
|
+
): Promise<void> | void {
|
|
150
|
+
const { swaggerUI } = configContext.resolve(HttpConfig);
|
|
151
|
+
const { globalPrefix, swagger, cors } = this.options ?? {};
|
|
152
|
+
if (globalPrefix) {
|
|
153
|
+
app.setGlobalPrefix(globalPrefix);
|
|
154
|
+
}
|
|
155
|
+
if (cors) {
|
|
156
|
+
app.enableCors(cors);
|
|
162
157
|
}
|
|
163
158
|
|
|
164
159
|
if (swaggerUI || swagger?.file) {
|
|
@@ -183,17 +178,5 @@ export class HttpTransport implements IHttpTransport {
|
|
|
183
178
|
}
|
|
184
179
|
}
|
|
185
180
|
|
|
186
|
-
|
|
187
|
-
return HealthHttpController;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
getMetricsController(): Constructor<Controller> {
|
|
191
|
-
return MetricsHttpController;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
createHttpOptions(configContext: ConfigContext): HttpOptions {
|
|
195
|
-
const { host, port } = configContext.resolve(HttpConfig);
|
|
196
|
-
|
|
197
|
-
return { host, port };
|
|
198
|
-
}
|
|
181
|
+
abstract createHttpAdapter(httpConfig: HttpConfig): AbstractHttpAdapter;
|
|
199
182
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { ExecutionContext } from '@nestjs/common';
|
|
2
|
-
import type { Controller, INestApplication } from '@nestjs/common/interfaces';
|
|
3
|
-
import type { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
|
|
4
|
-
import type { AbstractHttpAdapter } from '@nestjs/core';
|
|
5
|
-
import type { Constructor, DeepPartial } from '@rsdk/common';
|
|
6
|
-
import type { ConfigContext, HttpOptions, IErrorsFormatter, IErrorsSender, IErrorsTransformer, IHttpTransport, NestModuleDefinitions, ProtocolTracingHeadersExtractor } from '@rsdk/core';
|
|
7
|
-
import { HttpConfig } from '../http.config';
|
|
8
|
-
import type { SwaggerOptions } from '../http.transport';
|
|
9
|
-
export declare abstract class AbstractRsdkHttpTransport implements IHttpTransport {
|
|
10
|
-
getHeaderExtractor(): ProtocolTracingHeadersExtractor;
|
|
11
|
-
abstract readonly options?: {
|
|
12
|
-
cors?: CorsOptions;
|
|
13
|
-
globalPrefix?: string;
|
|
14
|
-
swagger?: DeepPartial<SwaggerOptions>;
|
|
15
|
-
};
|
|
16
|
-
matchByContext(ctx: ExecutionContext): boolean;
|
|
17
|
-
modules(): NestModuleDefinitions;
|
|
18
|
-
getErrorsFormatter(): IErrorsFormatter;
|
|
19
|
-
getErrorsSender(): IErrorsSender;
|
|
20
|
-
getErrorTransformers(): IErrorsTransformer[];
|
|
21
|
-
getProtocol(): string;
|
|
22
|
-
getHealthController(): Constructor<Controller>;
|
|
23
|
-
getMetricsController(): Constructor<Controller>;
|
|
24
|
-
createHttpOptions(configContext: ConfigContext): HttpOptions;
|
|
25
|
-
createAdapter(configContext: ConfigContext): AbstractHttpAdapter;
|
|
26
|
-
configureApp(app: INestApplication, configContext: ConfigContext): Promise<void> | void;
|
|
27
|
-
abstract createHttpAdapter(httpConfig: HttpConfig): AbstractHttpAdapter;
|
|
28
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AbstractRsdkHttpTransport = void 0;
|
|
4
|
-
const core_1 = require("@nestjs/core");
|
|
5
|
-
const swagger_1 = require("@nestjs/swagger");
|
|
6
|
-
const document_builder_1 = require("@nestjs/swagger/dist/document-builder");
|
|
7
|
-
const core_2 = require("@rsdk/core");
|
|
8
|
-
const node_fs_1 = require("node:fs");
|
|
9
|
-
const controllers_1 = require("../controllers");
|
|
10
|
-
const error_handling_1 = require("../error-handling");
|
|
11
|
-
const http_config_1 = require("../http.config");
|
|
12
|
-
const http_headers_1 = require("../http.headers");
|
|
13
|
-
const http_logger_interceptor_1 = require("../http-logger.interceptor");
|
|
14
|
-
class AbstractRsdkHttpTransport {
|
|
15
|
-
getHeaderExtractor() {
|
|
16
|
-
return {
|
|
17
|
-
extract(executionContext) {
|
|
18
|
-
// TODO:
|
|
19
|
-
const req = executionContext.switchToHttp().getRequest();
|
|
20
|
-
return new http_headers_1.HttpHeaders(req.headers).getTracingHeaders();
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
matchByContext(ctx) {
|
|
25
|
-
return ctx.getType() === 'http';
|
|
26
|
-
}
|
|
27
|
-
modules() {
|
|
28
|
-
return [
|
|
29
|
-
{
|
|
30
|
-
module: AbstractRsdkHttpTransport,
|
|
31
|
-
providers: [
|
|
32
|
-
{
|
|
33
|
-
provide: core_1.APP_INTERCEPTOR,
|
|
34
|
-
useClass: http_logger_interceptor_1.HttpLoggerInterceptor,
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
},
|
|
38
|
-
];
|
|
39
|
-
}
|
|
40
|
-
getErrorsFormatter() {
|
|
41
|
-
return new error_handling_1.HttpErrorsFormatter();
|
|
42
|
-
}
|
|
43
|
-
getErrorsSender() {
|
|
44
|
-
return new error_handling_1.HttpErrorsSender();
|
|
45
|
-
}
|
|
46
|
-
getErrorTransformers() {
|
|
47
|
-
return [new error_handling_1.HttpErrorsTransformer()];
|
|
48
|
-
}
|
|
49
|
-
getProtocol() {
|
|
50
|
-
return 'http';
|
|
51
|
-
}
|
|
52
|
-
getHealthController() {
|
|
53
|
-
return controllers_1.HealthHttpController;
|
|
54
|
-
}
|
|
55
|
-
getMetricsController() {
|
|
56
|
-
return controllers_1.MetricsHttpController;
|
|
57
|
-
}
|
|
58
|
-
createHttpOptions(configContext) {
|
|
59
|
-
const { host, port } = configContext.resolve(http_config_1.HttpConfig);
|
|
60
|
-
return {
|
|
61
|
-
host,
|
|
62
|
-
port,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
createAdapter(configContext) {
|
|
66
|
-
return this.createHttpAdapter(configContext.resolve(http_config_1.HttpConfig));
|
|
67
|
-
}
|
|
68
|
-
configureApp(app, configContext) {
|
|
69
|
-
const { swaggerUI } = configContext.resolve(http_config_1.HttpConfig);
|
|
70
|
-
const { globalPrefix, swagger, cors } = this.options ?? {};
|
|
71
|
-
if (globalPrefix) {
|
|
72
|
-
app.setGlobalPrefix(globalPrefix);
|
|
73
|
-
}
|
|
74
|
-
if (cors) {
|
|
75
|
-
app.enableCors(cors);
|
|
76
|
-
}
|
|
77
|
-
if (swaggerUI || swagger?.file) {
|
|
78
|
-
const builder = new document_builder_1.DocumentBuilder()
|
|
79
|
-
.setTitle(app.get(core_2.APP_NAME))
|
|
80
|
-
.setVersion(app.get(core_2.APP_VERSION))
|
|
81
|
-
.setDescription(app.get(core_2.APP_DESCRIPTION));
|
|
82
|
-
// Applies additional configuration from user
|
|
83
|
-
swagger?.configure?.(builder);
|
|
84
|
-
const openApiConfig = builder.build();
|
|
85
|
-
const spec = swagger_1.SwaggerModule.createDocument(app, openApiConfig);
|
|
86
|
-
if (swagger?.file) {
|
|
87
|
-
(0, node_fs_1.writeFileSync)(swagger.file, JSON.stringify(spec));
|
|
88
|
-
}
|
|
89
|
-
if (swaggerUI) {
|
|
90
|
-
swagger_1.SwaggerModule.setup(swagger?.url ?? '/swagger', app, spec);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
exports.AbstractRsdkHttpTransport = AbstractRsdkHttpTransport;
|
|
96
|
-
//# sourceMappingURL=abstract-rsdk-http-adapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-rsdk-http-adapter.js","sourceRoot":"","sources":["../../src/http-adapter/abstract-rsdk-http-adapter.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { ArgumentsHost } from '@nestjs/common';
|
|
2
|
-
import type { ProtocolTracingHeadersExtractor } from '@rsdk/core';
|
|
3
|
-
import type { TracingHeaders } from '@rsdk/core/dist/tracing/types';
|
|
4
|
-
export declare class HttpTracingExtractor implements ProtocolTracingHeadersExtractor {
|
|
5
|
-
extract(executionContext: ArgumentsHost): TracingHeaders;
|
|
6
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpTracingExtractor = void 0;
|
|
4
|
-
const http_headers_1 = require("./http.headers");
|
|
5
|
-
class HttpTracingExtractor {
|
|
6
|
-
extract(executionContext) {
|
|
7
|
-
// TODO:
|
|
8
|
-
const req = executionContext.switchToHttp().getRequest();
|
|
9
|
-
return new http_headers_1.HttpHeaders(req.headers).getTracingHeaders();
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.HttpTracingExtractor = HttpTracingExtractor;
|
|
13
|
-
//# sourceMappingURL=http.tracing-extractor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http.tracing-extractor.js","sourceRoot":"","sources":["../src/http.tracing-extractor.ts"],"names":[],"mappings":";;;AAIA,iDAA6C;AAE7C,MAAa,oBAAoB;IAC/B,OAAO,CAAC,gBAA+B;QACrC,QAAQ;QACR,MAAM,GAAG,GAAG,gBAAgB,CAAC,YAAY,EAAE,CAAC,UAAU,EAAO,CAAC;QAE9D,OAAO,IAAI,0BAAW,CACpB,GAAG,CAAC,OAAiC,CACtC,CAAC,iBAAiB,EAAE,CAAC;IACxB,CAAC;CACF;AATD,oDASC"}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import type { ArgumentsHost, ExecutionContext } from '@nestjs/common';
|
|
2
|
-
import type { Controller, INestApplication } from '@nestjs/common/interfaces';
|
|
3
|
-
import type { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
|
|
4
|
-
import type { AbstractHttpAdapter } from '@nestjs/core';
|
|
5
|
-
import { APP_INTERCEPTOR } from '@nestjs/core';
|
|
6
|
-
import { SwaggerModule } from '@nestjs/swagger';
|
|
7
|
-
import { DocumentBuilder as OriginalDocumentBuilder } from '@nestjs/swagger/dist/document-builder';
|
|
8
|
-
import type { Constructor, DeepPartial } from '@rsdk/common';
|
|
9
|
-
import type {
|
|
10
|
-
ConfigContext,
|
|
11
|
-
HttpOptions,
|
|
12
|
-
IErrorsFormatter,
|
|
13
|
-
IErrorsSender,
|
|
14
|
-
IErrorsTransformer,
|
|
15
|
-
IHttpTransport,
|
|
16
|
-
NestModuleDefinitions,
|
|
17
|
-
ProtocolTracingHeadersExtractor,
|
|
18
|
-
} from '@rsdk/core';
|
|
19
|
-
import { APP_DESCRIPTION, APP_NAME, APP_VERSION } from '@rsdk/core';
|
|
20
|
-
import type { TracingHeaders } from '@rsdk/core/dist/tracing/types';
|
|
21
|
-
import { writeFileSync } from 'node:fs';
|
|
22
|
-
|
|
23
|
-
import { HealthHttpController, MetricsHttpController } from '../controllers';
|
|
24
|
-
import {
|
|
25
|
-
HttpErrorsFormatter,
|
|
26
|
-
HttpErrorsSender,
|
|
27
|
-
HttpErrorsTransformer,
|
|
28
|
-
} from '../error-handling';
|
|
29
|
-
import { HttpConfig } from '../http.config';
|
|
30
|
-
import { HttpHeaders } from '../http.headers';
|
|
31
|
-
import type { SwaggerOptions } from '../http.transport';
|
|
32
|
-
import { HttpLoggerInterceptor } from '../http-logger.interceptor';
|
|
33
|
-
|
|
34
|
-
export abstract class AbstractRsdkHttpTransport implements IHttpTransport {
|
|
35
|
-
getHeaderExtractor(): ProtocolTracingHeadersExtractor {
|
|
36
|
-
return {
|
|
37
|
-
extract(executionContext: ArgumentsHost): TracingHeaders {
|
|
38
|
-
// TODO:
|
|
39
|
-
const req = executionContext.switchToHttp().getRequest<any>();
|
|
40
|
-
|
|
41
|
-
return new HttpHeaders(
|
|
42
|
-
req.headers as Record<string, string>,
|
|
43
|
-
).getTracingHeaders();
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
abstract readonly options?: {
|
|
49
|
-
// CORS middleware options
|
|
50
|
-
cors?: CorsOptions;
|
|
51
|
-
|
|
52
|
-
// Global prefix (will be used in app.setGlobalPrefix())
|
|
53
|
-
globalPrefix?: string;
|
|
54
|
-
|
|
55
|
-
// Swagger options. You can configure OpenAPI document
|
|
56
|
-
// builder or set file to write on application start
|
|
57
|
-
// NOTE: SwaggerUI is enabled or disabled by HTTP_SWAGGER_UI_ENABLED
|
|
58
|
-
// (true by default).
|
|
59
|
-
|
|
60
|
-
// TODO: It terrible to generate file on application start. Would be
|
|
61
|
-
// much better if we could get OpenAPI spec on demand without actually
|
|
62
|
-
// running the app. Unfortunately there is no way to do it in Nest.js 9.
|
|
63
|
-
// Planned in https://jira.rvision.pro/browse/PFM-134
|
|
64
|
-
swagger?: DeepPartial<SwaggerOptions>;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
matchByContext(ctx: ExecutionContext): boolean {
|
|
68
|
-
return ctx.getType() === 'http';
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
modules(): NestModuleDefinitions {
|
|
72
|
-
return [
|
|
73
|
-
{
|
|
74
|
-
module: AbstractRsdkHttpTransport as any,
|
|
75
|
-
providers: [
|
|
76
|
-
{
|
|
77
|
-
provide: APP_INTERCEPTOR,
|
|
78
|
-
useClass: HttpLoggerInterceptor,
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
},
|
|
82
|
-
];
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
getErrorsFormatter(): IErrorsFormatter {
|
|
86
|
-
return new HttpErrorsFormatter();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
getErrorsSender(): IErrorsSender {
|
|
90
|
-
return new HttpErrorsSender();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
getErrorTransformers(): IErrorsTransformer[] {
|
|
94
|
-
return [new HttpErrorsTransformer()];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
getProtocol(): string {
|
|
98
|
-
return 'http';
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
getHealthController(): Constructor<Controller> {
|
|
102
|
-
return HealthHttpController;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
getMetricsController(): Constructor<Controller> {
|
|
106
|
-
return MetricsHttpController;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
createHttpOptions(configContext: ConfigContext): HttpOptions {
|
|
110
|
-
const { host, port } = configContext.resolve(HttpConfig);
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
host,
|
|
114
|
-
port,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
createAdapter(configContext: ConfigContext): AbstractHttpAdapter {
|
|
119
|
-
return this.createHttpAdapter(configContext.resolve(HttpConfig));
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
configureApp(
|
|
123
|
-
app: INestApplication,
|
|
124
|
-
configContext: ConfigContext,
|
|
125
|
-
): Promise<void> | void {
|
|
126
|
-
const { swaggerUI } = configContext.resolve(HttpConfig);
|
|
127
|
-
const { globalPrefix, swagger, cors } = this.options ?? {};
|
|
128
|
-
if (globalPrefix) {
|
|
129
|
-
app.setGlobalPrefix(globalPrefix);
|
|
130
|
-
}
|
|
131
|
-
if (cors) {
|
|
132
|
-
app.enableCors(cors);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (swaggerUI || swagger?.file) {
|
|
136
|
-
const builder = new OriginalDocumentBuilder()
|
|
137
|
-
.setTitle(app.get(APP_NAME))
|
|
138
|
-
.setVersion(app.get(APP_VERSION))
|
|
139
|
-
.setDescription(app.get(APP_DESCRIPTION));
|
|
140
|
-
|
|
141
|
-
// Applies additional configuration from user
|
|
142
|
-
swagger?.configure?.(builder);
|
|
143
|
-
|
|
144
|
-
const openApiConfig = builder.build();
|
|
145
|
-
const spec = SwaggerModule.createDocument(app, openApiConfig);
|
|
146
|
-
|
|
147
|
-
if (swagger?.file) {
|
|
148
|
-
writeFileSync(swagger.file, JSON.stringify(spec));
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (swaggerUI) {
|
|
152
|
-
SwaggerModule.setup(swagger?.url ?? '/swagger', app, spec);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
abstract createHttpAdapter(httpConfig: HttpConfig): AbstractHttpAdapter;
|
|
158
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ArgumentsHost } from '@nestjs/common';
|
|
2
|
-
import type { ProtocolTracingHeadersExtractor } from '@rsdk/core';
|
|
3
|
-
import type { TracingHeaders } from '@rsdk/core/dist/tracing/types';
|
|
4
|
-
|
|
5
|
-
import { HttpHeaders } from './http.headers';
|
|
6
|
-
|
|
7
|
-
export class HttpTracingExtractor implements ProtocolTracingHeadersExtractor {
|
|
8
|
-
extract(executionContext: ArgumentsHost): TracingHeaders {
|
|
9
|
-
// TODO:
|
|
10
|
-
const req = executionContext.switchToHttp().getRequest<any>();
|
|
11
|
-
|
|
12
|
-
return new HttpHeaders(
|
|
13
|
-
req.headers as Record<string, string>,
|
|
14
|
-
).getTracingHeaders();
|
|
15
|
-
}
|
|
16
|
-
}
|