@venok/http 1.0.1-canary.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/adapter/adapter.d.ts +57 -0
- package/adapter/adapter.js +58 -0
- package/adapter/host.d.ts +27 -0
- package/adapter/host.js +33 -0
- package/application/application.d.ts +18 -0
- package/application/application.js +51 -0
- package/application/config.d.ts +16 -0
- package/application/config.js +47 -0
- package/application/http.module-defenition.d.ts +8 -0
- package/application/http.module-defenition.js +6 -0
- package/application/http.module.d.ts +3 -0
- package/application/http.module.js +21 -0
- package/application/http.service.d.ts +11 -0
- package/application/http.service.js +43 -0
- package/application/starter.d.ts +41 -0
- package/application/starter.js +140 -0
- package/constants.d.ts +12 -0
- package/constants.js +15 -0
- package/context/context.d.ts +56 -0
- package/context/context.js +102 -0
- package/context/response.controller.d.ts +30 -0
- package/context/response.controller.js +86 -0
- package/decorators/controller.decorator.d.ts +82 -0
- package/decorators/controller.decorator.js +53 -0
- package/decorators/header.decorator.d.ts +12 -0
- package/decorators/header.decorator.js +23 -0
- package/decorators/http-code.decorator.d.ts +9 -0
- package/decorators/http-code.decorator.js +19 -0
- package/decorators/index.d.ts +9 -0
- package/decorators/index.js +25 -0
- package/decorators/redirect.decorator.d.ts +6 -0
- package/decorators/redirect.decorator.js +16 -0
- package/decorators/render.decorator.d.ts +10 -0
- package/decorators/render.decorator.js +20 -0
- package/decorators/request-mapping.decorator.d.ts +78 -0
- package/decorators/request-mapping.decorator.js +98 -0
- package/decorators/route-params.decorator.d.ts +378 -0
- package/decorators/route-params.decorator.js +227 -0
- package/decorators/sse.decorator.d.ts +6 -0
- package/decorators/sse.decorator.js +20 -0
- package/decorators/version.decorator.d.ts +7 -0
- package/decorators/version.decorator.js +20 -0
- package/enums/http-status.enum.d.ts +53 -0
- package/enums/http-status.enum.js +57 -0
- package/enums/index.d.ts +4 -0
- package/enums/index.js +20 -0
- package/enums/request-method.enum.d.ts +11 -0
- package/enums/request-method.enum.js +15 -0
- package/enums/route-paramtypes.enum.d.ts +14 -0
- package/enums/route-paramtypes.enum.js +18 -0
- package/enums/version-type.enum.d.ts +9 -0
- package/enums/version-type.enum.js +13 -0
- package/errors/bad-gateway.exception.d.ts +33 -0
- package/errors/bad-gateway.exception.js +41 -0
- package/errors/bad-request.exception.d.ts +33 -0
- package/errors/bad-request.exception.js +41 -0
- package/errors/conflict.exception.d.ts +33 -0
- package/errors/conflict.exception.js +41 -0
- package/errors/forbidden.exception.d.ts +33 -0
- package/errors/forbidden.exception.js +41 -0
- package/errors/gateway-timeout.exception.d.ts +33 -0
- package/errors/gateway-timeout.exception.js +41 -0
- package/errors/gone.exception.d.ts +33 -0
- package/errors/gone.exception.js +41 -0
- package/errors/http-version-not-supported.exception.d.ts +33 -0
- package/errors/http-version-not-supported.exception.js +41 -0
- package/errors/http.exception.d.ts +79 -0
- package/errors/http.exception.js +123 -0
- package/errors/im-a-teapot.exception.d.ts +36 -0
- package/errors/im-a-teapot.exception.js +44 -0
- package/errors/index.d.ts +11 -0
- package/errors/index.js +27 -0
- package/errors/internal-server-error.exception.d.ts +33 -0
- package/errors/internal-server-error.exception.js +41 -0
- package/errors/invalid-middleware-configuration.exception.d.ts +4 -0
- package/errors/invalid-middleware-configuration.exception.js +11 -0
- package/errors/invalid-middleware.exception.d.ts +4 -0
- package/errors/invalid-middleware.exception.js +11 -0
- package/errors/not-found.exception.d.ts +33 -0
- package/errors/not-found.exception.js +41 -0
- package/errors/unknown-request-mapping.exception.d.ts +5 -0
- package/errors/unknown-request-mapping.exception.js +11 -0
- package/exceptions/messages.d.ts +4 -0
- package/exceptions/messages.js +13 -0
- package/explorers/path.explorer.d.ts +8 -0
- package/explorers/path.explorer.js +38 -0
- package/explorers/router.explorer.d.ts +51 -0
- package/explorers/router.explorer.js +195 -0
- package/factory/context-id.factory.d.ts +41 -0
- package/factory/context-id.factory.js +52 -0
- package/factory/index.d.ts +4 -0
- package/factory/index.js +20 -0
- package/factory/method.factory.d.ts +5 -0
- package/factory/method.factory.js +30 -0
- package/factory/params.factory.d.ts +5 -0
- package/factory/params.factory.js +39 -0
- package/factory/path.factory.d.ts +13 -0
- package/factory/path.factory.js +95 -0
- package/filters/context.d.ts +9 -0
- package/filters/context.js +15 -0
- package/filters/filter.d.ts +22 -0
- package/filters/filter.js +78 -0
- package/helpers/adapter.helper.d.ts +27 -0
- package/helpers/adapter.helper.js +37 -0
- package/helpers/exclude-route.helper.d.ts +4 -0
- package/helpers/exclude-route.helper.js +18 -0
- package/helpers/flatten-routes.helper.d.ts +5 -0
- package/helpers/flatten-routes.helper.js +27 -0
- package/helpers/index.d.ts +6 -0
- package/helpers/index.js +22 -0
- package/helpers/messages.helper.d.ts +6 -0
- package/helpers/messages.helper.js +25 -0
- package/helpers/path.helper.d.ts +3 -0
- package/helpers/path.helper.js +13 -0
- package/helpers/sse.helper.d.ts +45 -0
- package/helpers/sse.helper.js +83 -0
- package/index.d.ts +1 -0
- package/index.js +3 -0
- package/interfaces/http/cors.interface.d.ts +58 -0
- package/interfaces/http/cors.interface.js +2 -0
- package/interfaces/http/exception.interface.d.ts +6 -0
- package/interfaces/http/exception.interface.js +2 -0
- package/interfaces/http/exclude-route.interface.d.ts +15 -0
- package/interfaces/http/exclude-route.interface.js +2 -0
- package/interfaces/http/index.d.ts +10 -0
- package/interfaces/http/index.js +26 -0
- package/interfaces/http/message-event.interface.d.ts +6 -0
- package/interfaces/http/message-event.interface.js +2 -0
- package/interfaces/http/module.inteface.d.ts +5 -0
- package/interfaces/http/module.inteface.js +2 -0
- package/interfaces/http/options.interface.d.ts +127 -0
- package/interfaces/http/options.interface.js +2 -0
- package/interfaces/http/path-metadata.interface.d.ts +31 -0
- package/interfaces/http/path-metadata.interface.js +2 -0
- package/interfaces/http/prefix-options.interface.d.ts +7 -0
- package/interfaces/http/prefix-options.interface.js +2 -0
- package/interfaces/http/raw-request.d.ts +4 -0
- package/interfaces/http/raw-request.js +2 -0
- package/interfaces/http/routes.interface.d.ts +7 -0
- package/interfaces/http/routes.interface.js +2 -0
- package/interfaces/http/server.interface.d.ts +54 -0
- package/interfaces/http/server.interface.js +2 -0
- package/interfaces/index.d.ts +3 -0
- package/interfaces/index.js +19 -0
- package/interfaces/middleware/config-proxy.interface.d.ts +23 -0
- package/interfaces/middleware/config-proxy.interface.js +2 -0
- package/interfaces/middleware/configuration.interface.d.ts +12 -0
- package/interfaces/middleware/configuration.interface.js +2 -0
- package/interfaces/middleware/consumer.interface.d.ts +16 -0
- package/interfaces/middleware/consumer.interface.js +2 -0
- package/interfaces/middleware/index.d.ts +4 -0
- package/interfaces/middleware/index.js +20 -0
- package/interfaces/middleware/middleware.interface.d.ts +7 -0
- package/interfaces/middleware/middleware.interface.js +2 -0
- package/interfaces/router/callback-paramtypes.interface.d.ts +1 -0
- package/interfaces/router/callback-paramtypes.interface.js +2 -0
- package/interfaces/router/definition.interface.d.ts +10 -0
- package/interfaces/router/definition.interface.js +2 -0
- package/interfaces/router/index.d.ts +3 -0
- package/interfaces/router/index.js +19 -0
- package/interfaces/router/version-options.interface.d.ts +92 -0
- package/interfaces/router/version-options.interface.js +9 -0
- package/middleware/builder.d.ts +15 -0
- package/middleware/builder.js +78 -0
- package/middleware/container.d.ts +13 -0
- package/middleware/container.js +50 -0
- package/middleware/extractor.d.ts +15 -0
- package/middleware/extractor.js +50 -0
- package/middleware/index.d.ts +1 -0
- package/middleware/index.js +17 -0
- package/middleware/module.d.ts +33 -0
- package/middleware/module.js +180 -0
- package/middleware/resolver.d.ts +10 -0
- package/middleware/resolver.js +27 -0
- package/middleware/routes-mapper.d.ts +19 -0
- package/middleware/routes-mapper.js +111 -0
- package/middleware/utils.d.ts +8 -0
- package/middleware/utils.js +86 -0
- package/package.json +41 -0
- package/router/module.d.ts +18 -0
- package/router/module.js +88 -0
- package/router/resolver.d.ts +31 -0
- package/router/resolver.js +128 -0
- package/storage/http-instance.storage.d.ts +9 -0
- package/storage/http-instance.storage.js +19 -0
- package/stream/index.d.ts +1 -0
- package/stream/index.js +17 -0
- package/stream/interfaces/index.d.ts +2 -0
- package/stream/interfaces/index.js +18 -0
- package/stream/interfaces/streamable-handler-response.interface.d.ts +12 -0
- package/stream/interfaces/streamable-handler-response.interface.js +2 -0
- package/stream/interfaces/streamable-options.interface.d.ts +10 -0
- package/stream/interfaces/streamable-options.interface.js +2 -0
- package/stream/streamable-file.d.ts +22 -0
- package/stream/streamable-file.js +55 -0
- package/test/context/response.controller.spec.d.ts +1 -0
- package/test/context/response.controller.spec.js +328 -0
- package/test/decorators/controller.decorator.spec.d.ts +1 -0
- package/test/decorators/controller.decorator.spec.js +113 -0
- package/test/decorators/header.decorator.spec.d.ts +1 -0
- package/test/decorators/header.decorator.spec.js +33 -0
- package/test/decorators/http-code.decorator.spec.d.ts +1 -0
- package/test/decorators/http-code.decorator.spec.js +30 -0
- package/test/decorators/redirect.decorator.spec.d.ts +1 -0
- package/test/decorators/redirect.decorator.spec.js +36 -0
- package/test/decorators/render.decorator.spec.d.ts +1 -0
- package/test/decorators/render.decorator.spec.js +30 -0
- package/test/decorators/request-mapping.decorator.spec.d.ts +1 -0
- package/test/decorators/request-mapping.decorator.spec.js +85 -0
- package/test/decorators/route-params.decorator.spec.d.ts +1 -0
- package/test/decorators/route-params.decorator.spec.js +493 -0
- package/test/decorators/sse.decorator.spec.d.ts +1 -0
- package/test/decorators/sse.decorator.spec.js +35 -0
- package/test/decorators/version.decorator.spec.d.ts +1 -0
- package/test/decorators/version.decorator.spec.js +43 -0
- package/test/exceptions/handler.spec.d.ts +1 -0
- package/test/exceptions/handler.spec.js +145 -0
- package/test/exceptions/proxy.spec.d.ts +1 -0
- package/test/exceptions/proxy.spec.js +74 -0
- package/test/explorers/path.explorer.spec.d.ts +1 -0
- package/test/explorers/path.explorer.spec.js +190 -0
- package/test/explorers/router.explorer.spec.d.ts +1 -0
- package/test/explorers/router.explorer.spec.js +206 -0
- package/test/factory/method.factory.spec.d.ts +1 -0
- package/test/factory/method.factory.spec.js +33 -0
- package/test/factory/params.factory.spec.d.ts +1 -0
- package/test/factory/params.factory.spec.js +104 -0
- package/test/factory/path.factory.spec.d.ts +1 -0
- package/test/factory/path.factory.spec.js +260 -0
- package/test/filters/context.spec.d.ts +1 -0
- package/test/filters/context.spec.js +96 -0
- package/test/filters/filter.spec.d.ts +1 -0
- package/test/filters/filter.spec.js +96 -0
- package/test/helpers/flatten-routes.helper.spec.d.ts +1 -0
- package/test/helpers/flatten-routes.helper.spec.js +131 -0
- package/test/helpers/sse.helper.spec.d.ts +1 -0
- package/test/helpers/sse.helper.spec.js +132 -0
- package/test/middleware/builder.spec.d.ts +1 -0
- package/test/middleware/builder.spec.js +235 -0
- package/test/middleware/container.spec.d.ts +1 -0
- package/test/middleware/container.spec.js +81 -0
- package/test/middleware/module.spec.d.ts +1 -0
- package/test/middleware/module.spec.js +206 -0
- package/test/middleware/route-info-path-extractor.spec.d.ts +1 -0
- package/test/middleware/route-info-path-extractor.spec.js +123 -0
- package/test/middleware/routes-mapper.spec.d.ts +1 -0
- package/test/middleware/routes-mapper.spec.js +162 -0
- package/test/middleware/utils.spec.d.ts +1 -0
- package/test/middleware/utils.spec.js +132 -0
- package/test/router/module.spec.d.ts +1 -0
- package/test/router/module.spec.js +40 -0
- package/test/router/resolver.spec.d.ts +1 -0
- package/test/router/resolver.spec.js +326 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { RequestMethod } from "@venok/http/enums";
|
|
2
|
+
import { CorsOptions, CorsOptionsDelegate, HttpServer, RequestHandler, VenokApplicationOptions, VersioningOptions, VersionValue } from "@venok/http/interfaces";
|
|
3
|
+
/**
|
|
4
|
+
* @publicApi
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class AbstractHttpAdapter<TServer = any, TRequest = any, TResponse = any> implements HttpServer<TRequest, TResponse> {
|
|
7
|
+
protected instance?: any;
|
|
8
|
+
protected httpServer: TServer;
|
|
9
|
+
constructor(instance?: any);
|
|
10
|
+
init(): Promise<void>;
|
|
11
|
+
use(...args: any[]): any;
|
|
12
|
+
get(handler: RequestHandler): any;
|
|
13
|
+
get(path: any, handler: RequestHandler): any;
|
|
14
|
+
post(handler: RequestHandler): any;
|
|
15
|
+
post(path: any, handler: RequestHandler): any;
|
|
16
|
+
head(handler: RequestHandler): any;
|
|
17
|
+
head(path: any, handler: RequestHandler): any;
|
|
18
|
+
delete(handler: RequestHandler): any;
|
|
19
|
+
delete(path: any, handler: RequestHandler): any;
|
|
20
|
+
put(handler: RequestHandler): any;
|
|
21
|
+
put(path: any, handler: RequestHandler): any;
|
|
22
|
+
patch(handler: RequestHandler): any;
|
|
23
|
+
patch(path: any, handler: RequestHandler): any;
|
|
24
|
+
all(handler: RequestHandler): any;
|
|
25
|
+
all(path: any, handler: RequestHandler): any;
|
|
26
|
+
search(port: string | number, callback?: () => void): any;
|
|
27
|
+
search(port: string | number, hostname: string, callback?: () => void): any;
|
|
28
|
+
options(handler: RequestHandler): any;
|
|
29
|
+
options(path: any, handler: RequestHandler): any;
|
|
30
|
+
listen(port: string | number, callback?: () => void): void;
|
|
31
|
+
listen(port: string | number, hostname: string, callback?: () => void): void;
|
|
32
|
+
getHttpServer(): TServer;
|
|
33
|
+
setHttpServer(httpServer: TServer): void;
|
|
34
|
+
setInstance<T = any>(instance: T): void;
|
|
35
|
+
getInstance<T = any>(): T;
|
|
36
|
+
abstract close(): this | Promise<this>;
|
|
37
|
+
abstract initHttpServer(options: VenokApplicationOptions): this;
|
|
38
|
+
abstract useStaticAssets(...args: any[]): this;
|
|
39
|
+
abstract setViewEngine(engine: string): this;
|
|
40
|
+
abstract getRequestHostname(request: any): any;
|
|
41
|
+
abstract getRequestMethod(request: any): any;
|
|
42
|
+
abstract getRequestUrl(request: any): any;
|
|
43
|
+
abstract status(response: any, statusCode: number): any;
|
|
44
|
+
abstract reply(response: any, body: any, statusCode?: number): any;
|
|
45
|
+
abstract end(response: any, message?: string): any;
|
|
46
|
+
abstract render(response: any, view: string, options: any): any;
|
|
47
|
+
abstract redirect(response: any, statusCode: number, url: string): any;
|
|
48
|
+
abstract setErrorHandler(handler: Function, prefix?: string): any;
|
|
49
|
+
abstract setNotFoundHandler(handler: Function, prefix?: string): any;
|
|
50
|
+
abstract isHeadersSent(response: any): any;
|
|
51
|
+
abstract setHeader(response: any, name: string, value: string): any;
|
|
52
|
+
abstract registerParserMiddleware(prefix?: string, rawBody?: boolean): any;
|
|
53
|
+
abstract enableCors(options: CorsOptions | CorsOptionsDelegate<TRequest>, prefix?: string): any;
|
|
54
|
+
abstract createMiddlewareFactory(requestMethod: RequestMethod): ((path: string, callback: Function) => any) | Promise<(path: string, callback: Function) => any>;
|
|
55
|
+
abstract getType(): string;
|
|
56
|
+
abstract applyVersionFilter(handler: Function, version: VersionValue, versioningOptions: VersioningOptions): (req: TRequest, res: TResponse, next: () => void) => Function;
|
|
57
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractHttpAdapter = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @publicApi
|
|
6
|
+
*/
|
|
7
|
+
class AbstractHttpAdapter {
|
|
8
|
+
constructor(instance) {
|
|
9
|
+
this.instance = instance;
|
|
10
|
+
}
|
|
11
|
+
async init() { }
|
|
12
|
+
use(...args) {
|
|
13
|
+
return this.instance.use(...args);
|
|
14
|
+
}
|
|
15
|
+
get(...args) {
|
|
16
|
+
return this.instance.get(...args);
|
|
17
|
+
}
|
|
18
|
+
post(...args) {
|
|
19
|
+
return this.instance.post(...args);
|
|
20
|
+
}
|
|
21
|
+
head(...args) {
|
|
22
|
+
return this.instance.head(...args);
|
|
23
|
+
}
|
|
24
|
+
delete(...args) {
|
|
25
|
+
return this.instance.delete(...args);
|
|
26
|
+
}
|
|
27
|
+
put(...args) {
|
|
28
|
+
return this.instance.put(...args);
|
|
29
|
+
}
|
|
30
|
+
patch(...args) {
|
|
31
|
+
return this.instance.patch(...args);
|
|
32
|
+
}
|
|
33
|
+
all(...args) {
|
|
34
|
+
return this.instance.all(...args);
|
|
35
|
+
}
|
|
36
|
+
search(port, hostname, callback) {
|
|
37
|
+
return this.instance.search(port, hostname, callback);
|
|
38
|
+
}
|
|
39
|
+
options(...args) {
|
|
40
|
+
return this.instance.options(...args);
|
|
41
|
+
}
|
|
42
|
+
listen(port, hostname, callback) {
|
|
43
|
+
return this.instance.listen(port, hostname, callback);
|
|
44
|
+
}
|
|
45
|
+
getHttpServer() {
|
|
46
|
+
return this.httpServer;
|
|
47
|
+
}
|
|
48
|
+
setHttpServer(httpServer) {
|
|
49
|
+
this.httpServer = httpServer;
|
|
50
|
+
}
|
|
51
|
+
setInstance(instance) {
|
|
52
|
+
this.instance = instance;
|
|
53
|
+
}
|
|
54
|
+
getInstance() {
|
|
55
|
+
return this.instance;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.AbstractHttpAdapter = AbstractHttpAdapter;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AbstractHttpAdapter } from "@venok/http/adapter/adapter";
|
|
2
|
+
/**
|
|
3
|
+
* Defines the `HttpAdapterHost` object.
|
|
4
|
+
*
|
|
5
|
+
* `HttpAdapterHost` wraps the underlying
|
|
6
|
+
* platform-specific `HttpAdapter`. The `HttpAdapter` is a wrapper around the underlying
|
|
7
|
+
* native HTTP server library (e.g., Express). The `HttpAdapterHost` object
|
|
8
|
+
* provides methods to `get` and `set` the underlying HttpAdapter.
|
|
9
|
+
*
|
|
10
|
+
* @publicApi
|
|
11
|
+
*/
|
|
12
|
+
export declare class HttpAdapterHost<T extends AbstractHttpAdapter = AbstractHttpAdapter> {
|
|
13
|
+
private _httpAdapter?;
|
|
14
|
+
/**
|
|
15
|
+
* Accessor for the underlying `HttpAdapter`
|
|
16
|
+
*
|
|
17
|
+
* @param httpAdapter reference to the `HttpAdapter` to be set
|
|
18
|
+
*/
|
|
19
|
+
set httpAdapter(httpAdapter: T);
|
|
20
|
+
/**
|
|
21
|
+
* Accessor for the underlying `HttpAdapter`
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* `const httpAdapter = adapterHost.httpAdapter;`
|
|
25
|
+
*/
|
|
26
|
+
get httpAdapter(): T;
|
|
27
|
+
}
|
package/adapter/host.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpAdapterHost = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Defines the `HttpAdapterHost` object.
|
|
6
|
+
*
|
|
7
|
+
* `HttpAdapterHost` wraps the underlying
|
|
8
|
+
* platform-specific `HttpAdapter`. The `HttpAdapter` is a wrapper around the underlying
|
|
9
|
+
* native HTTP server library (e.g., Express). The `HttpAdapterHost` object
|
|
10
|
+
* provides methods to `get` and `set` the underlying HttpAdapter.
|
|
11
|
+
*
|
|
12
|
+
* @publicApi
|
|
13
|
+
*/
|
|
14
|
+
class HttpAdapterHost {
|
|
15
|
+
/**
|
|
16
|
+
* Accessor for the underlying `HttpAdapter`
|
|
17
|
+
*
|
|
18
|
+
* @param httpAdapter reference to the `HttpAdapter` to be set
|
|
19
|
+
*/
|
|
20
|
+
set httpAdapter(httpAdapter) {
|
|
21
|
+
this._httpAdapter = httpAdapter;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Accessor for the underlying `HttpAdapter`
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* `const httpAdapter = adapterHost.httpAdapter;`
|
|
28
|
+
*/
|
|
29
|
+
get httpAdapter() {
|
|
30
|
+
return this._httpAdapter;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.HttpAdapterHost = HttpAdapterHost;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CorsOptions, CorsOptionsDelegate, GlobalPrefixOptions, HttpServer, VersioningOptions } from "../interfaces";
|
|
2
|
+
import { HttpConfig } from "./config";
|
|
3
|
+
import { AbstractHttpAdapter } from "../adapter/adapter";
|
|
4
|
+
export declare class HttpApplication {
|
|
5
|
+
private readonly httpAdapter;
|
|
6
|
+
private readonly config;
|
|
7
|
+
private start;
|
|
8
|
+
constructor(httpAdapter: HttpServer, config: HttpConfig);
|
|
9
|
+
use(...args: [any, any?]): this;
|
|
10
|
+
getHttpAdapter(): AbstractHttpAdapter;
|
|
11
|
+
enableCors(options?: CorsOptions | CorsOptionsDelegate<any>): this;
|
|
12
|
+
enableVersioning(options?: VersioningOptions): this;
|
|
13
|
+
setGlobalPrefix(prefix: string, options?: GlobalPrefixOptions): this;
|
|
14
|
+
useStaticAssets(options: any): this;
|
|
15
|
+
useStaticAssets(path: string, options?: any): this;
|
|
16
|
+
setBaseViewsDir(path: string | string[]): this;
|
|
17
|
+
setViewEngine(engineOrOptions: any): this;
|
|
18
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpApplication = void 0;
|
|
4
|
+
const enums_1 = require("../enums");
|
|
5
|
+
const utils_1 = require("../middleware/utils");
|
|
6
|
+
class HttpApplication {
|
|
7
|
+
constructor(httpAdapter, config) {
|
|
8
|
+
this.httpAdapter = httpAdapter;
|
|
9
|
+
this.config = config;
|
|
10
|
+
this.start = false;
|
|
11
|
+
}
|
|
12
|
+
use(...args) {
|
|
13
|
+
this.httpAdapter.use(...args);
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
getHttpAdapter() {
|
|
17
|
+
return this.httpAdapter;
|
|
18
|
+
}
|
|
19
|
+
enableCors(options) {
|
|
20
|
+
this.httpAdapter.enableCors(options);
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
enableVersioning(options = { type: enums_1.VersioningType.URI }) {
|
|
24
|
+
this.config.enableVersioning(options);
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
setGlobalPrefix(prefix, options) {
|
|
28
|
+
this.config.setGlobalPrefix(prefix);
|
|
29
|
+
if (options) {
|
|
30
|
+
const exclude = options?.exclude ? (0, utils_1.mapToExcludeRoute)(options.exclude) : [];
|
|
31
|
+
this.config.setGlobalPrefixOptions({
|
|
32
|
+
...options,
|
|
33
|
+
exclude,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
useStaticAssets(pathOrOptions, options) {
|
|
39
|
+
this.httpAdapter.useStaticAssets && this.httpAdapter.useStaticAssets(pathOrOptions, options);
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
setBaseViewsDir(path) {
|
|
43
|
+
this.httpAdapter.setBaseViewsDir && this.httpAdapter.setBaseViewsDir(path);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
setViewEngine(engineOrOptions) {
|
|
47
|
+
this.httpAdapter.setViewEngine && this.httpAdapter.setViewEngine(engineOrOptions);
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.HttpApplication = HttpApplication;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ExcludeRouteMetadata, GlobalPrefixOptions, VersioningOptions } from "../interfaces";
|
|
2
|
+
export declare class HttpConfig {
|
|
3
|
+
private globalPrefix;
|
|
4
|
+
private globalPrefixOptions;
|
|
5
|
+
private versioningOptions;
|
|
6
|
+
private readonly httpInstanceStorage;
|
|
7
|
+
setHttpAdapter(httpAdapter: any): void;
|
|
8
|
+
getHttpAdapterRef(): import("../adapter/adapter").AbstractHttpAdapter<any, any, any>;
|
|
9
|
+
getHttpAdapterHostRef(): import("../adapter/host").HttpAdapterHost<import("../adapter/adapter").AbstractHttpAdapter<any, any, any>>;
|
|
10
|
+
setGlobalPrefix(prefix: string): void;
|
|
11
|
+
getGlobalPrefix(): string;
|
|
12
|
+
setGlobalPrefixOptions(options: GlobalPrefixOptions<ExcludeRouteMetadata>): void;
|
|
13
|
+
getGlobalPrefixOptions(): GlobalPrefixOptions<ExcludeRouteMetadata>;
|
|
14
|
+
enableVersioning(options: VersioningOptions): void;
|
|
15
|
+
getVersioning(): VersioningOptions | undefined;
|
|
16
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpConfig = void 0;
|
|
4
|
+
const http_instance_storage_1 = require("../storage/http-instance.storage");
|
|
5
|
+
class HttpConfig {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.globalPrefix = "";
|
|
8
|
+
this.globalPrefixOptions = {};
|
|
9
|
+
this.httpInstanceStorage = new http_instance_storage_1.HttpInstanceStorage();
|
|
10
|
+
}
|
|
11
|
+
setHttpAdapter(httpAdapter) {
|
|
12
|
+
this.httpInstanceStorage.httpAdapter = httpAdapter;
|
|
13
|
+
if (!this.httpInstanceStorage.httpAdapterHost)
|
|
14
|
+
return;
|
|
15
|
+
const host = this.httpInstanceStorage.httpAdapterHost;
|
|
16
|
+
host.httpAdapter = httpAdapter;
|
|
17
|
+
}
|
|
18
|
+
getHttpAdapterRef() {
|
|
19
|
+
return this.httpInstanceStorage.httpAdapter;
|
|
20
|
+
}
|
|
21
|
+
getHttpAdapterHostRef() {
|
|
22
|
+
return this.httpInstanceStorage.httpAdapterHost;
|
|
23
|
+
}
|
|
24
|
+
setGlobalPrefix(prefix) {
|
|
25
|
+
this.globalPrefix = prefix;
|
|
26
|
+
}
|
|
27
|
+
getGlobalPrefix() {
|
|
28
|
+
return this.globalPrefix;
|
|
29
|
+
}
|
|
30
|
+
setGlobalPrefixOptions(options) {
|
|
31
|
+
this.globalPrefixOptions = options;
|
|
32
|
+
}
|
|
33
|
+
getGlobalPrefixOptions() {
|
|
34
|
+
return this.globalPrefixOptions;
|
|
35
|
+
}
|
|
36
|
+
enableVersioning(options) {
|
|
37
|
+
if (Array.isArray(options.defaultVersion)) {
|
|
38
|
+
// Drop duplicated versions
|
|
39
|
+
options.defaultVersion = Array.from(new Set(options.defaultVersion));
|
|
40
|
+
}
|
|
41
|
+
this.versioningOptions = options;
|
|
42
|
+
}
|
|
43
|
+
getVersioning() {
|
|
44
|
+
return this.versioningOptions;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.HttpConfig = HttpConfig;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HttpApplication } from "./application";
|
|
2
|
+
import { AbstractHttpAdapter } from "../adapter/adapter";
|
|
3
|
+
export interface HttpAppOptions {
|
|
4
|
+
port: number;
|
|
5
|
+
callback?: (app: HttpApplication) => void;
|
|
6
|
+
adapter?: AbstractHttpAdapter;
|
|
7
|
+
}
|
|
8
|
+
export declare const HttpConfigurableModuleClass: import("@venok/core/module").ConfigurableModuleCls<HttpAppOptions, "register", "create", {}>, HTTP_APP_OPTIONS: string | symbol;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.HTTP_APP_OPTIONS = exports.HttpConfigurableModuleClass = void 0;
|
|
5
|
+
const module_1 = require("../../core/module");
|
|
6
|
+
_a = new module_1.ConfigurableModuleBuilder().build(), exports.HttpConfigurableModuleClass = _a.ConfigurableModuleClass, exports.HTTP_APP_OPTIONS = _a.MODULE_OPTIONS_TOKEN;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.HttpModule = void 0;
|
|
10
|
+
const http_module_defenition_1 = require("./http.module-defenition");
|
|
11
|
+
const core_1 = require("../../core/index.ts");
|
|
12
|
+
const module_1 = require("../../core/discovery/module");
|
|
13
|
+
const http_service_1 = require("./http.service");
|
|
14
|
+
let HttpModule = class HttpModule extends http_module_defenition_1.HttpConfigurableModuleClass {
|
|
15
|
+
};
|
|
16
|
+
exports.HttpModule = HttpModule;
|
|
17
|
+
exports.HttpModule = HttpModule = __decorate([
|
|
18
|
+
(0, core_1.Module)({
|
|
19
|
+
providers: [module_1.DiscoveryModule, http_service_1.HttpCoreService],
|
|
20
|
+
})
|
|
21
|
+
], HttpModule);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { VenokContainer } from "@venok/core";
|
|
2
|
+
import { OnApplicationShutdown, OnModuleInit } from "@venok/core/interfaces/hooks";
|
|
3
|
+
import { HttpAppOptions } from "./http.module-defenition";
|
|
4
|
+
export declare class HttpCoreService implements OnModuleInit, OnApplicationShutdown {
|
|
5
|
+
private readonly container;
|
|
6
|
+
private readonly options;
|
|
7
|
+
private httpStarter;
|
|
8
|
+
constructor(container: VenokContainer, options: Required<HttpAppOptions>);
|
|
9
|
+
onModuleInit(): Promise<any>;
|
|
10
|
+
onApplicationShutdown(signal?: string): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.HttpCoreService = void 0;
|
|
16
|
+
const core_1 = require("../../core/index.ts");
|
|
17
|
+
const config_1 = require("./config");
|
|
18
|
+
const starter_1 = require("./starter");
|
|
19
|
+
const graph_inspector_1 = require("../../core/inspector/graph-inspector");
|
|
20
|
+
const application_1 = require("./application");
|
|
21
|
+
const http_module_defenition_1 = require("./http.module-defenition");
|
|
22
|
+
let HttpCoreService = class HttpCoreService {
|
|
23
|
+
constructor(container, options) {
|
|
24
|
+
this.container = container;
|
|
25
|
+
this.options = options;
|
|
26
|
+
}
|
|
27
|
+
async onModuleInit() {
|
|
28
|
+
const httpConfig = new config_1.HttpConfig();
|
|
29
|
+
httpConfig.setHttpAdapter(this.options.adapter);
|
|
30
|
+
this.httpStarter = new starter_1.HttpStarter(this.container, this.options.adapter, this.container.applicationConfig, httpConfig, new graph_inspector_1.GraphInspector(this.container));
|
|
31
|
+
this.options.callback && this.options.callback(new application_1.HttpApplication(this.options.adapter, httpConfig));
|
|
32
|
+
await this.httpStarter.listen(this.options.port);
|
|
33
|
+
}
|
|
34
|
+
async onApplicationShutdown(signal) {
|
|
35
|
+
await this.httpStarter.dispose();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.HttpCoreService = HttpCoreService;
|
|
39
|
+
exports.HttpCoreService = HttpCoreService = __decorate([
|
|
40
|
+
(0, core_1.Injectable)(),
|
|
41
|
+
__param(1, (0, core_1.Inject)(http_module_defenition_1.HTTP_APP_OPTIONS)),
|
|
42
|
+
__metadata("design:paramtypes", [core_1.VenokContainer, Object])
|
|
43
|
+
], HttpCoreService);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ApplicationConfig, VenokContainer } from "@venok/core";
|
|
2
|
+
import { Logger } from "@venok/core/services/logger.service";
|
|
3
|
+
import { HttpServer } from "../interfaces";
|
|
4
|
+
import { HttpConfig } from "./config";
|
|
5
|
+
import { GraphInspector } from "@venok/core/inspector/graph-inspector";
|
|
6
|
+
/**
|
|
7
|
+
* @publicApi
|
|
8
|
+
*/
|
|
9
|
+
export declare class HttpStarter {
|
|
10
|
+
private readonly container;
|
|
11
|
+
private readonly httpAdapter;
|
|
12
|
+
private readonly config;
|
|
13
|
+
private readonly httpConfig;
|
|
14
|
+
private readonly graphInspector;
|
|
15
|
+
private readonly appOptions;
|
|
16
|
+
private readonly injector;
|
|
17
|
+
protected readonly logger: Logger;
|
|
18
|
+
private readonly middlewareModule;
|
|
19
|
+
private readonly middlewareContainer;
|
|
20
|
+
private readonly routesResolver;
|
|
21
|
+
private httpServer;
|
|
22
|
+
private isListening;
|
|
23
|
+
constructor(container: VenokContainer, httpAdapter: HttpServer, config: ApplicationConfig, httpConfig: HttpConfig, graphInspector: GraphInspector, appOptions?: any);
|
|
24
|
+
dispose(): Promise<void>;
|
|
25
|
+
registerHttpServer(): void;
|
|
26
|
+
getUnderlyingHttpServer<T>(): T;
|
|
27
|
+
createServer<T = any>(): T;
|
|
28
|
+
registerModules(): Promise<void>;
|
|
29
|
+
init(): Promise<this>;
|
|
30
|
+
registerParserMiddleware(): void;
|
|
31
|
+
registerRouter(): Promise<void>;
|
|
32
|
+
registerRouterHooks(): Promise<void>;
|
|
33
|
+
getHttpServer(): any;
|
|
34
|
+
listen(port: number | string): Promise<any>;
|
|
35
|
+
listen(port: number | string, hostname: string): Promise<any>;
|
|
36
|
+
getUrl(): Promise<string>;
|
|
37
|
+
private formatAddress;
|
|
38
|
+
private host;
|
|
39
|
+
private getProtocol;
|
|
40
|
+
private registerMiddleware;
|
|
41
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpStarter = void 0;
|
|
4
|
+
const injector_1 = require("../../core/injector/injector");
|
|
5
|
+
const shared_helper_1 = require("../../core/helpers/shared.helper");
|
|
6
|
+
const os_1 = require("os");
|
|
7
|
+
const helpers_1 = require("../helpers");
|
|
8
|
+
const logger_service_1 = require("../../core/services/logger.service");
|
|
9
|
+
const container_1 = require("../middleware/container");
|
|
10
|
+
const module_1 = require("../middleware/module");
|
|
11
|
+
const resolver_1 = require("../router/resolver");
|
|
12
|
+
/**
|
|
13
|
+
* @publicApi
|
|
14
|
+
*/
|
|
15
|
+
class HttpStarter {
|
|
16
|
+
constructor(container, httpAdapter, config, httpConfig, graphInspector, appOptions = {}) {
|
|
17
|
+
this.container = container;
|
|
18
|
+
this.httpAdapter = httpAdapter;
|
|
19
|
+
this.config = config;
|
|
20
|
+
this.httpConfig = httpConfig;
|
|
21
|
+
this.graphInspector = graphInspector;
|
|
22
|
+
this.appOptions = appOptions;
|
|
23
|
+
this.logger = new logger_service_1.Logger(HttpStarter.name, {
|
|
24
|
+
timestamp: true,
|
|
25
|
+
});
|
|
26
|
+
this.isListening = false;
|
|
27
|
+
this.registerHttpServer();
|
|
28
|
+
this.middlewareContainer = new container_1.MiddlewareContainer(this.container);
|
|
29
|
+
this.injector = new injector_1.Injector({ preview: this.appOptions.preview });
|
|
30
|
+
this.middlewareModule = new module_1.MiddlewareModule();
|
|
31
|
+
this.routesResolver = new resolver_1.RoutesResolver(this.container, this.config, this.httpConfig, this.injector, this.graphInspector);
|
|
32
|
+
}
|
|
33
|
+
async dispose() {
|
|
34
|
+
this.httpAdapter && (await this.httpAdapter.close());
|
|
35
|
+
}
|
|
36
|
+
registerHttpServer() {
|
|
37
|
+
this.httpServer = this.createServer();
|
|
38
|
+
}
|
|
39
|
+
getUnderlyingHttpServer() {
|
|
40
|
+
return this.httpAdapter.getHttpServer();
|
|
41
|
+
}
|
|
42
|
+
createServer() {
|
|
43
|
+
this.httpAdapter.initHttpServer(this.appOptions);
|
|
44
|
+
return this.httpAdapter.getHttpServer();
|
|
45
|
+
}
|
|
46
|
+
async registerModules() {
|
|
47
|
+
await this.middlewareModule.register(this.middlewareContainer, this.container, this.config, this.httpConfig, this.injector, this.httpAdapter, this.graphInspector, this.appOptions);
|
|
48
|
+
}
|
|
49
|
+
async init() {
|
|
50
|
+
this.httpAdapter.init && (await this.httpAdapter.init());
|
|
51
|
+
const useBodyParser = this.appOptions && this.appOptions.bodyParser !== false;
|
|
52
|
+
useBodyParser && this.registerParserMiddleware();
|
|
53
|
+
await this.registerModules();
|
|
54
|
+
await this.registerRouter();
|
|
55
|
+
await this.registerRouterHooks();
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
registerParserMiddleware() {
|
|
59
|
+
const prefix = this.httpConfig.getGlobalPrefix();
|
|
60
|
+
const rawBody = !!this.appOptions?.rawBody;
|
|
61
|
+
this.httpAdapter.registerParserMiddleware(prefix, rawBody);
|
|
62
|
+
}
|
|
63
|
+
async registerRouter() {
|
|
64
|
+
await this.registerMiddleware(this.httpAdapter);
|
|
65
|
+
const prefix = this.httpConfig.getGlobalPrefix();
|
|
66
|
+
const basePath = (0, helpers_1.addLeadingSlash)(prefix);
|
|
67
|
+
this.routesResolver.resolve(this.httpAdapter, basePath);
|
|
68
|
+
}
|
|
69
|
+
async registerRouterHooks() {
|
|
70
|
+
this.routesResolver.registerNotFoundHandler();
|
|
71
|
+
this.routesResolver.registerExceptionHandler();
|
|
72
|
+
}
|
|
73
|
+
getHttpServer() {
|
|
74
|
+
return this.httpServer;
|
|
75
|
+
}
|
|
76
|
+
async listen(port, ...args) {
|
|
77
|
+
await this.init();
|
|
78
|
+
return new Promise((resolve, reject) => {
|
|
79
|
+
const errorHandler = (e) => {
|
|
80
|
+
this.logger.error(e?.toString?.());
|
|
81
|
+
reject(e);
|
|
82
|
+
};
|
|
83
|
+
this.httpServer.once("error", errorHandler);
|
|
84
|
+
const isCallbackInOriginalArgs = (0, shared_helper_1.isFunction)(args[args.length - 1]);
|
|
85
|
+
const listenFnArgs = isCallbackInOriginalArgs ? args.slice(0, args.length - 1) : args;
|
|
86
|
+
this.httpAdapter.listen(port, ...listenFnArgs, (...originalCallbackArgs) => {
|
|
87
|
+
if (originalCallbackArgs[0] instanceof Error)
|
|
88
|
+
return reject(originalCallbackArgs[0]);
|
|
89
|
+
const address = this.httpServer.address();
|
|
90
|
+
if (address) {
|
|
91
|
+
this.httpServer.removeListener("error", errorHandler);
|
|
92
|
+
this.isListening = true;
|
|
93
|
+
resolve(this.httpServer);
|
|
94
|
+
}
|
|
95
|
+
if (isCallbackInOriginalArgs) {
|
|
96
|
+
args[args.length - 1](...originalCallbackArgs);
|
|
97
|
+
}
|
|
98
|
+
this.logger.log((0, helpers_1.VENOK_HTTP_SERVER_START)(port));
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
async getUrl() {
|
|
103
|
+
return new Promise((resolve, reject) => {
|
|
104
|
+
const address = this.httpServer.address();
|
|
105
|
+
resolve(this.formatAddress(address));
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
formatAddress(address) {
|
|
109
|
+
if ((0, shared_helper_1.isString)(address)) {
|
|
110
|
+
if ((0, os_1.platform)() === "win32")
|
|
111
|
+
return address;
|
|
112
|
+
const basePath = encodeURIComponent(address);
|
|
113
|
+
return `${this.getProtocol()}+unix://${basePath}`;
|
|
114
|
+
}
|
|
115
|
+
let host = this.host();
|
|
116
|
+
if (address && address.family === "IPv6") {
|
|
117
|
+
if (host === "::")
|
|
118
|
+
host = "[::1]";
|
|
119
|
+
else
|
|
120
|
+
host = `[${host}]`;
|
|
121
|
+
}
|
|
122
|
+
else if (host === "0.0.0.0") {
|
|
123
|
+
host = "127.0.0.1";
|
|
124
|
+
}
|
|
125
|
+
return `${this.getProtocol()}://${host}:${address.port}`;
|
|
126
|
+
}
|
|
127
|
+
host() {
|
|
128
|
+
const address = this.httpServer.address();
|
|
129
|
+
if ((0, shared_helper_1.isString)(address))
|
|
130
|
+
return undefined;
|
|
131
|
+
return address && address.address;
|
|
132
|
+
}
|
|
133
|
+
getProtocol() {
|
|
134
|
+
return this.appOptions && this.appOptions.httpsOptions ? "https" : "http";
|
|
135
|
+
}
|
|
136
|
+
async registerMiddleware(instance) {
|
|
137
|
+
await this.middlewareModule.registerMiddleware(this.middlewareContainer, instance);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.HttpStarter = HttpStarter;
|
package/constants.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const HOST_METADATA = "host";
|
|
2
|
+
export declare const PATH_METADATA = "path";
|
|
3
|
+
export declare const HEADERS_METADATA = "__headers__";
|
|
4
|
+
export declare const REDIRECT_METADATA = "__redirect__";
|
|
5
|
+
export declare const RESPONSE_PASSTHROUGH_METADATA = "__responsePassthrough__";
|
|
6
|
+
export declare const SSE_METADATA = "__sse__";
|
|
7
|
+
export declare const VERSION_METADATA = "__version__";
|
|
8
|
+
export declare const CONTROLLER_WATERMARK = "__controller__";
|
|
9
|
+
export declare const RENDER_METADATA = "__renderTemplate__";
|
|
10
|
+
export declare const HTTP_CODE_METADATA = "__httpCode__";
|
|
11
|
+
export declare const METHOD_METADATA = "method";
|
|
12
|
+
export declare const REQUEST_CONTEXT_ID: unique symbol;
|
package/constants.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REQUEST_CONTEXT_ID = exports.METHOD_METADATA = exports.HTTP_CODE_METADATA = exports.RENDER_METADATA = exports.CONTROLLER_WATERMARK = exports.VERSION_METADATA = exports.SSE_METADATA = exports.RESPONSE_PASSTHROUGH_METADATA = exports.REDIRECT_METADATA = exports.HEADERS_METADATA = exports.PATH_METADATA = exports.HOST_METADATA = void 0;
|
|
4
|
+
exports.HOST_METADATA = "host";
|
|
5
|
+
exports.PATH_METADATA = "path";
|
|
6
|
+
exports.HEADERS_METADATA = "__headers__";
|
|
7
|
+
exports.REDIRECT_METADATA = "__redirect__";
|
|
8
|
+
exports.RESPONSE_PASSTHROUGH_METADATA = "__responsePassthrough__";
|
|
9
|
+
exports.SSE_METADATA = "__sse__";
|
|
10
|
+
exports.VERSION_METADATA = "__version__";
|
|
11
|
+
exports.CONTROLLER_WATERMARK = "__controller__";
|
|
12
|
+
exports.RENDER_METADATA = "__renderTemplate__";
|
|
13
|
+
exports.HTTP_CODE_METADATA = "__httpCode__";
|
|
14
|
+
exports.METHOD_METADATA = "method";
|
|
15
|
+
exports.REQUEST_CONTEXT_ID = Symbol("REQUEST_CONTEXT_ID");
|