@tsed/platform-http 8.11.1 → 8.12.0-rc.1
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/lib/esm/common/builder/PlatformBuilder.js +0 -1
- package/lib/esm/common/builder/__fixtures__/PlatformCustom.js +0 -1
- package/lib/esm/common/config/interfaces/PlatformJsonMapperSettings.js +0 -1
- package/lib/esm/common/config/interfaces/PlatformMulterSettings.js +0 -1
- package/lib/esm/common/config/interfaces/PlatformRouterSettings.js +0 -1
- package/lib/esm/common/config/interfaces/PlatformStaticsSettings.js +0 -1
- package/lib/esm/common/config/services/PlatformConfiguration.js +0 -1
- package/lib/esm/common/constants/routerOptions.js +0 -1
- package/lib/esm/common/decorators/PlatformProvider.js +0 -1
- package/lib/esm/common/decorators/multer/multerFileSize.js +0 -1
- package/lib/esm/common/decorators/multer/multerOptions.js +0 -1
- package/lib/esm/common/decorators/multer/multipartFile.js +0 -1
- package/lib/esm/common/decorators/params/error.js +0 -1
- package/lib/esm/common/decorators/params/next.js +0 -1
- package/lib/esm/common/decorators/params/request.js +0 -1
- package/lib/esm/common/decorators/params/response.js +0 -1
- package/lib/esm/common/domain/AnyToPromiseWithCtx.js +0 -1
- package/lib/esm/common/domain/EndpointMetadata.js +0 -1
- package/lib/esm/common/domain/PlatformContext.js +0 -1
- package/lib/esm/common/domain/PlatformRouteDetails.js +0 -1
- package/lib/esm/common/exports.js +0 -1
- package/lib/esm/common/fn/adapter.js +0 -1
- package/lib/esm/common/fn/application.js +0 -1
- package/lib/esm/common/index.js +0 -1
- package/lib/esm/common/interfaces/AfterInit.js +0 -1
- package/lib/esm/common/interfaces/AfterListen.js +0 -1
- package/lib/esm/common/interfaces/AfterRoutesInit.js +0 -1
- package/lib/esm/common/interfaces/BeforeInit.js +0 -1
- package/lib/esm/common/interfaces/BeforeListen.js +0 -1
- package/lib/esm/common/interfaces/BeforeRoutesInit.js +0 -1
- package/lib/esm/common/interfaces/HandlerType.js +0 -1
- package/lib/esm/common/interfaces/IncomingEvent.js +0 -1
- package/lib/esm/common/interfaces/OnReady.js +0 -1
- package/lib/esm/common/interfaces/OnRequest.js +0 -1
- package/lib/esm/common/interfaces/OnResponse.js +0 -1
- package/lib/esm/common/interfaces/OnRoutesInit.js +0 -1
- package/lib/esm/common/interfaces/PlatformRouteOptions.js +0 -1
- package/lib/esm/common/interfaces/ResponseErrorObject.js +0 -1
- package/lib/esm/common/interfaces/Route.js +0 -1
- package/lib/esm/common/middlewares/PlatformAcceptMimesMiddleware.js +0 -1
- package/lib/esm/common/middlewares/PlatformMulterMiddleware.js +0 -1
- package/lib/esm/common/services/Platform.js +0 -1
- package/lib/esm/common/services/PlatformAdapter.js +0 -1
- package/lib/esm/common/services/PlatformApplication.js +0 -1
- package/lib/esm/common/services/PlatformHandler.js +0 -1
- package/lib/esm/common/services/PlatformRequest.js +0 -1
- package/lib/esm/common/services/PlatformResponse.js +0 -1
- package/lib/esm/common/utils/closeServer.js +0 -1
- package/lib/esm/common/utils/createContext.js +0 -1
- package/lib/esm/common/utils/createHttpServer.js +0 -1
- package/lib/esm/common/utils/createHttpsServer.js +0 -1
- package/lib/esm/common/utils/createInjector.js +0 -1
- package/lib/esm/common/utils/createServer.js +0 -1
- package/lib/esm/common/utils/ensureContext.js +0 -1
- package/lib/esm/common/utils/getConfiguration.js +0 -1
- package/lib/esm/common/utils/getStaticsOptions.js +0 -1
- package/lib/esm/common/utils/listenServer.js +0 -1
- package/lib/esm/common/utils/mapReturnedResponse.js +0 -1
- package/lib/esm/common/utils/printRoutes.js +0 -1
- package/lib/esm/common/utils/resolveControllers.js +0 -1
- package/lib/esm/common/utils/setResponseHeaders.js +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/testing/FakeAdapter.js +0 -1
- package/lib/esm/testing/FakeResponse.js +0 -1
- package/lib/esm/testing/PlatformTest.js +0 -1
- package/lib/esm/testing/index.js +0 -1
- package/package.json +20 -17
- package/.barrelsby.json +0 -5
- package/lib/esm/common/builder/PlatformBuilder.js.map +0 -1
- package/lib/esm/common/builder/__fixtures__/PlatformCustom.js.map +0 -1
- package/lib/esm/common/config/interfaces/PlatformJsonMapperSettings.js.map +0 -1
- package/lib/esm/common/config/interfaces/PlatformMulterSettings.js.map +0 -1
- package/lib/esm/common/config/interfaces/PlatformRouterSettings.js.map +0 -1
- package/lib/esm/common/config/interfaces/PlatformStaticsSettings.js.map +0 -1
- package/lib/esm/common/config/services/PlatformConfiguration.js.map +0 -1
- package/lib/esm/common/constants/routerOptions.js.map +0 -1
- package/lib/esm/common/decorators/PlatformProvider.js.map +0 -1
- package/lib/esm/common/decorators/multer/multerFileSize.js.map +0 -1
- package/lib/esm/common/decorators/multer/multerOptions.js.map +0 -1
- package/lib/esm/common/decorators/multer/multipartFile.js.map +0 -1
- package/lib/esm/common/decorators/params/error.js.map +0 -1
- package/lib/esm/common/decorators/params/next.js.map +0 -1
- package/lib/esm/common/decorators/params/request.js.map +0 -1
- package/lib/esm/common/decorators/params/response.js.map +0 -1
- package/lib/esm/common/domain/AnyToPromiseWithCtx.js.map +0 -1
- package/lib/esm/common/domain/EndpointMetadata.js.map +0 -1
- package/lib/esm/common/domain/PlatformContext.js.map +0 -1
- package/lib/esm/common/domain/PlatformRouteDetails.js.map +0 -1
- package/lib/esm/common/exports.js.map +0 -1
- package/lib/esm/common/fn/adapter.js.map +0 -1
- package/lib/esm/common/fn/application.js.map +0 -1
- package/lib/esm/common/index.js.map +0 -1
- package/lib/esm/common/interfaces/AfterInit.js.map +0 -1
- package/lib/esm/common/interfaces/AfterListen.js.map +0 -1
- package/lib/esm/common/interfaces/AfterRoutesInit.js.map +0 -1
- package/lib/esm/common/interfaces/BeforeInit.js.map +0 -1
- package/lib/esm/common/interfaces/BeforeListen.js.map +0 -1
- package/lib/esm/common/interfaces/BeforeRoutesInit.js.map +0 -1
- package/lib/esm/common/interfaces/HandlerType.js.map +0 -1
- package/lib/esm/common/interfaces/IncomingEvent.js.map +0 -1
- package/lib/esm/common/interfaces/OnReady.js.map +0 -1
- package/lib/esm/common/interfaces/OnRequest.js.map +0 -1
- package/lib/esm/common/interfaces/OnResponse.js.map +0 -1
- package/lib/esm/common/interfaces/OnRoutesInit.js.map +0 -1
- package/lib/esm/common/interfaces/PlatformRouteOptions.js.map +0 -1
- package/lib/esm/common/interfaces/ResponseErrorObject.js.map +0 -1
- package/lib/esm/common/interfaces/Route.js.map +0 -1
- package/lib/esm/common/middlewares/PlatformAcceptMimesMiddleware.js.map +0 -1
- package/lib/esm/common/middlewares/PlatformMulterMiddleware.js.map +0 -1
- package/lib/esm/common/services/Platform.js.map +0 -1
- package/lib/esm/common/services/PlatformAdapter.js.map +0 -1
- package/lib/esm/common/services/PlatformApplication.js.map +0 -1
- package/lib/esm/common/services/PlatformHandler.js.map +0 -1
- package/lib/esm/common/services/PlatformRequest.js.map +0 -1
- package/lib/esm/common/services/PlatformResponse.js.map +0 -1
- package/lib/esm/common/utils/closeServer.js.map +0 -1
- package/lib/esm/common/utils/createContext.js.map +0 -1
- package/lib/esm/common/utils/createHttpServer.js.map +0 -1
- package/lib/esm/common/utils/createHttpsServer.js.map +0 -1
- package/lib/esm/common/utils/createInjector.js.map +0 -1
- package/lib/esm/common/utils/createServer.js.map +0 -1
- package/lib/esm/common/utils/ensureContext.js.map +0 -1
- package/lib/esm/common/utils/getConfiguration.js.map +0 -1
- package/lib/esm/common/utils/getStaticsOptions.js.map +0 -1
- package/lib/esm/common/utils/listenServer.js.map +0 -1
- package/lib/esm/common/utils/mapReturnedResponse.js.map +0 -1
- package/lib/esm/common/utils/printRoutes.js.map +0 -1
- package/lib/esm/common/utils/resolveControllers.js.map +0 -1
- package/lib/esm/common/utils/setResponseHeaders.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/testing/FakeAdapter.js.map +0 -1
- package/lib/esm/testing/FakeResponse.js.map +0 -1
- package/lib/esm/testing/PlatformTest.js.map +0 -1
- package/lib/esm/testing/index.js.map +0 -1
- package/src/common/builder/PlatformBuilder.spec.ts +0 -331
- package/src/common/builder/PlatformBuilder.ts +0 -426
- package/src/common/builder/__fixtures__/PlatformCustom.ts +0 -39
- package/src/common/config/interfaces/PlatformJsonMapperSettings.ts +0 -11
- package/src/common/config/interfaces/PlatformMulterSettings.ts +0 -22
- package/src/common/config/interfaces/PlatformRouterSettings.ts +0 -11
- package/src/common/config/interfaces/PlatformStaticsSettings.ts +0 -23
- package/src/common/config/services/PlatformConfiguration.spec.ts +0 -181
- package/src/common/config/services/PlatformConfiguration.ts +0 -158
- package/src/common/constants/routerOptions.ts +0 -1
- package/src/common/decorators/PlatformProvider.ts +0 -14
- package/src/common/decorators/multer/multerFileSize.ts +0 -31
- package/src/common/decorators/multer/multerOptions.ts +0 -45
- package/src/common/decorators/multer/multipartFile.ts +0 -51
- package/src/common/decorators/params/error.spec.ts +0 -15
- package/src/common/decorators/params/error.ts +0 -16
- package/src/common/decorators/params/next.spec.ts +0 -15
- package/src/common/decorators/params/next.ts +0 -31
- package/src/common/decorators/params/request.spec.ts +0 -50
- package/src/common/decorators/params/request.ts +0 -86
- package/src/common/decorators/params/response.spec.ts +0 -37
- package/src/common/decorators/params/response.ts +0 -74
- package/src/common/domain/AnyToPromiseWithCtx.spec.ts +0 -20
- package/src/common/domain/AnyToPromiseWithCtx.ts +0 -30
- package/src/common/domain/EndpointMetadata.ts +0 -1
- package/src/common/domain/PlatformContext.spec.ts +0 -124
- package/src/common/domain/PlatformContext.ts +0 -136
- package/src/common/domain/PlatformRouteDetails.ts +0 -7
- package/src/common/exports.ts +0 -4
- package/src/common/fn/adapter.ts +0 -42
- package/src/common/fn/application.ts +0 -11
- package/src/common/index.ts +0 -61
- package/src/common/interfaces/AfterInit.ts +0 -3
- package/src/common/interfaces/AfterListen.ts +0 -3
- package/src/common/interfaces/AfterRoutesInit.ts +0 -3
- package/src/common/interfaces/BeforeInit.ts +0 -3
- package/src/common/interfaces/BeforeListen.ts +0 -3
- package/src/common/interfaces/BeforeRoutesInit.ts +0 -3
- package/src/common/interfaces/HandlerType.ts +0 -12
- package/src/common/interfaces/IncomingEvent.ts +0 -6
- package/src/common/interfaces/OnReady.ts +0 -3
- package/src/common/interfaces/OnRequest.ts +0 -5
- package/src/common/interfaces/OnResponse.ts +0 -5
- package/src/common/interfaces/OnRoutesInit.ts +0 -3
- package/src/common/interfaces/PlatformRouteOptions.ts +0 -17
- package/src/common/interfaces/ResponseErrorObject.ts +0 -8
- package/src/common/interfaces/Route.ts +0 -12
- package/src/common/middlewares/PlatformAcceptMimesMiddleware.spec.ts +0 -215
- package/src/common/middlewares/PlatformAcceptMimesMiddleware.ts +0 -34
- package/src/common/middlewares/PlatformMulterMiddleware.ts +0 -6
- package/src/common/services/Platform.spec.ts +0 -145
- package/src/common/services/Platform.ts +0 -79
- package/src/common/services/PlatformAdapter.ts +0 -102
- package/src/common/services/PlatformApplication.spec.ts +0 -89
- package/src/common/services/PlatformApplication.ts +0 -38
- package/src/common/services/PlatformHandler.spec.ts +0 -152
- package/src/common/services/PlatformHandler.ts +0 -137
- package/src/common/services/PlatformRequest.spec.ts +0 -185
- package/src/common/services/PlatformRequest.ts +0 -182
- package/src/common/services/PlatformResponse.spec.ts +0 -364
- package/src/common/services/PlatformResponse.ts +0 -393
- package/src/common/utils/closeServer.spec.ts +0 -11
- package/src/common/utils/closeServer.ts +0 -8
- package/src/common/utils/createContext.spec.ts +0 -111
- package/src/common/utils/createContext.ts +0 -52
- package/src/common/utils/createHttpServer.spec.ts +0 -75
- package/src/common/utils/createHttpServer.ts +0 -16
- package/src/common/utils/createHttpsServer.spec.ts +0 -74
- package/src/common/utils/createHttpsServer.ts +0 -17
- package/src/common/utils/createInjector.spec.ts +0 -42
- package/src/common/utils/createInjector.ts +0 -25
- package/src/common/utils/createServer.ts +0 -52
- package/src/common/utils/ensureContext.spec.ts +0 -41
- package/src/common/utils/ensureContext.ts +0 -17
- package/src/common/utils/getConfiguration.spec.ts +0 -163
- package/src/common/utils/getConfiguration.ts +0 -34
- package/src/common/utils/getStaticsOptions.spec.ts +0 -27
- package/src/common/utils/getStaticsOptions.ts +0 -24
- package/src/common/utils/listenServer.ts +0 -18
- package/src/common/utils/mapReturnedResponse.spec.ts +0 -35
- package/src/common/utils/mapReturnedResponse.ts +0 -10
- package/src/common/utils/printRoutes.spec.ts +0 -19
- package/src/common/utils/printRoutes.ts +0 -40
- package/src/common/utils/resolveControllers.spec.ts +0 -40
- package/src/common/utils/resolveControllers.ts +0 -54
- package/src/common/utils/setResponseHeaders.spec.ts +0 -84
- package/src/common/utils/setResponseHeaders.ts +0 -31
- package/src/index.ts +0 -2
- package/src/testing/FakeAdapter.ts +0 -69
- package/src/testing/FakeResponse.ts +0 -115
- package/src/testing/PlatformTest.spec.ts +0 -53
- package/src/testing/PlatformTest.ts +0 -161
- package/src/testing/index.ts +0 -5
- package/vitest.config.mts +0 -25
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import Https from "node:https";
|
|
2
|
-
|
|
3
|
-
import {configuration, destroyInjector, injector, InjectorService} from "@tsed/di";
|
|
4
|
-
|
|
5
|
-
import {createHttpsServer} from "./createHttpsServer.js";
|
|
6
|
-
|
|
7
|
-
describe("createHttpsServer", () => {
|
|
8
|
-
afterEach(() => {
|
|
9
|
-
vi.resetAllMocks();
|
|
10
|
-
});
|
|
11
|
-
afterEach(() => destroyInjector());
|
|
12
|
-
it("should create an instance of Https (Https port true)", async () => {
|
|
13
|
-
configuration().set("httpsPort", true);
|
|
14
|
-
|
|
15
|
-
const fn: any = vi.fn();
|
|
16
|
-
|
|
17
|
-
const listener = createHttpsServer(fn)!;
|
|
18
|
-
|
|
19
|
-
expect(!!injector().get(Https.Server)).toEqual(true);
|
|
20
|
-
expect(listener).toBeInstanceOf(Function);
|
|
21
|
-
|
|
22
|
-
const server = injector().get(Https.Server)!;
|
|
23
|
-
|
|
24
|
-
vi.spyOn(injector().logger, "info").mockReturnValue(undefined);
|
|
25
|
-
vi.spyOn(injector().logger, "debug").mockReturnValue(undefined);
|
|
26
|
-
vi.spyOn(server, "listen").mockReturnValue(undefined as never);
|
|
27
|
-
vi.spyOn(server, "address").mockReturnValue({port: 8089, address: "0.0.0.0"} as never);
|
|
28
|
-
vi.spyOn(server, "on").mockImplementation(((event: string, cb: any) => {
|
|
29
|
-
if (event === "listening") {
|
|
30
|
-
cb();
|
|
31
|
-
}
|
|
32
|
-
}) as never);
|
|
33
|
-
|
|
34
|
-
await listener();
|
|
35
|
-
|
|
36
|
-
expect(server.listen).toHaveBeenCalledWith(true, "0.0.0.0");
|
|
37
|
-
expect(injector().logger.info).toHaveBeenCalledWith("Listen server on https://0.0.0.0:8089");
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("should create a raw object (Https port false)", () => {
|
|
41
|
-
configuration().set("httpsPort", false);
|
|
42
|
-
|
|
43
|
-
const fn: any = vi.fn();
|
|
44
|
-
|
|
45
|
-
const listener = createHttpsServer(fn);
|
|
46
|
-
|
|
47
|
-
expect(injector().get(Https.Server)).toEqual(null);
|
|
48
|
-
|
|
49
|
-
expect(listener).toBeUndefined();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("should create an instance of Https (https port 0)", () => {
|
|
53
|
-
configuration().set("httpsPort", 0);
|
|
54
|
-
|
|
55
|
-
const fn: any = vi.fn();
|
|
56
|
-
|
|
57
|
-
const listener = createHttpsServer(fn);
|
|
58
|
-
|
|
59
|
-
expect(!!injector().get(Https.Server)).toEqual(true);
|
|
60
|
-
|
|
61
|
-
expect(listener).toBeInstanceOf(Function);
|
|
62
|
-
});
|
|
63
|
-
it("should create an instance of Https (https port + address)", () => {
|
|
64
|
-
configuration().set("httpsPort", "0.0.0.0:8080");
|
|
65
|
-
|
|
66
|
-
const fn: any = vi.fn();
|
|
67
|
-
|
|
68
|
-
const listener = createHttpsServer(fn);
|
|
69
|
-
|
|
70
|
-
expect(!!injector().get(Https.Server)).toEqual(true);
|
|
71
|
-
|
|
72
|
-
expect(listener).toBeInstanceOf(Function);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import Http from "node:http";
|
|
2
|
-
import Https from "node:https";
|
|
3
|
-
|
|
4
|
-
import {configuration, constant, InjectorService} from "@tsed/di";
|
|
5
|
-
|
|
6
|
-
import {createServer} from "./createServer.js";
|
|
7
|
-
|
|
8
|
-
export function createHttpsServer(requestListener?: Http.RequestListener) {
|
|
9
|
-
const httpsOptions = configuration().get("httpsOptions");
|
|
10
|
-
|
|
11
|
-
return createServer({
|
|
12
|
-
type: "https",
|
|
13
|
-
token: Https.Server,
|
|
14
|
-
port: constant("httpsPort"),
|
|
15
|
-
server: () => Https.createServer(httpsOptions, requestListener)
|
|
16
|
-
});
|
|
17
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import {Env} from "@tsed/core";
|
|
2
|
-
import {$log} from "@tsed/logger";
|
|
3
|
-
|
|
4
|
-
import {FakeAdapter} from "../../testing/FakeAdapter.js";
|
|
5
|
-
import {PlatformConfiguration} from "../config/services/PlatformConfiguration.js";
|
|
6
|
-
import {PlatformAdapter} from "../services/PlatformAdapter.js";
|
|
7
|
-
import {createInjector} from "./createInjector.js";
|
|
8
|
-
|
|
9
|
-
describe("createInjector", () => {
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
vi.spyOn($log, "stop").mockReturnValue(undefined as any);
|
|
12
|
-
});
|
|
13
|
-
afterEach(() => {
|
|
14
|
-
vi.resetAllMocks();
|
|
15
|
-
});
|
|
16
|
-
it("should create injector and stop logger in env Test", () => {
|
|
17
|
-
const settings = {
|
|
18
|
-
test: "test",
|
|
19
|
-
env: Env.TEST,
|
|
20
|
-
adapter: FakeAdapter
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const injector = createInjector(settings);
|
|
24
|
-
|
|
25
|
-
expect(injector.settings).toBeInstanceOf(PlatformConfiguration);
|
|
26
|
-
expect(injector.settings.get("test")).toEqual("test");
|
|
27
|
-
expect(injector.logger).toEqual($log);
|
|
28
|
-
expect(injector.get(PlatformAdapter)).toBeInstanceOf(FakeAdapter);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("should create injector", () => {
|
|
32
|
-
const settings = {
|
|
33
|
-
test: "test",
|
|
34
|
-
env: Env.PROD,
|
|
35
|
-
adapter: FakeAdapter
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const injector = createInjector(settings);
|
|
39
|
-
|
|
40
|
-
expect(injector.logger.stop).not.toHaveBeenCalled();
|
|
41
|
-
});
|
|
42
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {injector, setLoggerConfiguration} from "@tsed/di";
|
|
2
|
-
import {$log} from "@tsed/logger";
|
|
3
|
-
|
|
4
|
-
import {PlatformConfiguration} from "../config/services/PlatformConfiguration.js";
|
|
5
|
-
import {adapter as $adapter} from "../fn/adapter.js";
|
|
6
|
-
import {PlatformAdapter} from "../services/PlatformAdapter.js";
|
|
7
|
-
|
|
8
|
-
$log.name = "TSED";
|
|
9
|
-
|
|
10
|
-
export function createInjector(settings: Partial<TsED.Configuration>) {
|
|
11
|
-
const inj = injector();
|
|
12
|
-
inj.addProvider(PlatformConfiguration);
|
|
13
|
-
|
|
14
|
-
inj.settings = inj.invoke(PlatformConfiguration);
|
|
15
|
-
inj.logger = $log;
|
|
16
|
-
inj.settings.set(settings);
|
|
17
|
-
|
|
18
|
-
setLoggerConfiguration();
|
|
19
|
-
|
|
20
|
-
$adapter(settings.adapter);
|
|
21
|
-
|
|
22
|
-
inj.invoke(PlatformAdapter);
|
|
23
|
-
|
|
24
|
-
return inj;
|
|
25
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import Http from "node:http";
|
|
2
|
-
import Https from "node:https";
|
|
3
|
-
|
|
4
|
-
import {getHostInfoFromPort, ReturnHostInfoFromPort} from "@tsed/core";
|
|
5
|
-
import {configuration, injector, logger, ProviderScope, TokenProvider} from "@tsed/di";
|
|
6
|
-
import Http2 from "http2";
|
|
7
|
-
|
|
8
|
-
import {listenServer} from "./listenServer.js";
|
|
9
|
-
|
|
10
|
-
export interface CreateServerOptions {
|
|
11
|
-
token: TokenProvider;
|
|
12
|
-
type: "http" | "https";
|
|
13
|
-
port: string | false | undefined;
|
|
14
|
-
listen?: (hostInfo: ReturnHostInfoFromPort) => Promise<any>;
|
|
15
|
-
server: () => Http.Server | Https.Server | Http2.Http2Server;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type CreateServerReturn = () => Promise<Http.Server | Https.Server | Http2.Http2Server>;
|
|
19
|
-
|
|
20
|
-
export function createServer({token, type, port, server: get, listen}: CreateServerOptions): undefined | CreateServerReturn {
|
|
21
|
-
const server = port !== false ? get() : null;
|
|
22
|
-
|
|
23
|
-
injector().addProvider(token, {
|
|
24
|
-
scope: ProviderScope.SINGLETON,
|
|
25
|
-
useValue: server
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
injector().invoke(token);
|
|
29
|
-
|
|
30
|
-
if (server) {
|
|
31
|
-
const hostInfo = getHostInfoFromPort(type, port);
|
|
32
|
-
|
|
33
|
-
return async () => {
|
|
34
|
-
const url = `${hostInfo.protocol}://${hostInfo.address}:${port}`;
|
|
35
|
-
logger().debug(`Start server on ${url}`);
|
|
36
|
-
|
|
37
|
-
await (listen ? listen(hostInfo) : listenServer(server, hostInfo));
|
|
38
|
-
|
|
39
|
-
const address = server.address();
|
|
40
|
-
|
|
41
|
-
if (address && typeof address !== "string") {
|
|
42
|
-
hostInfo.address = address.address;
|
|
43
|
-
hostInfo.port = address.port;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
logger().info(`Listen server on ${hostInfo.toString()}`);
|
|
47
|
-
configuration().set(`${type}Port`, `${hostInfo.address}:${hostInfo.port}`);
|
|
48
|
-
|
|
49
|
-
return server;
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import {runInContext} from "@tsed/di";
|
|
2
|
-
|
|
3
|
-
import {PlatformTest} from "../../testing/PlatformTest.js";
|
|
4
|
-
import {ensureContext} from "./ensureContext.js";
|
|
5
|
-
|
|
6
|
-
describe("ensureContext()", () => {
|
|
7
|
-
beforeEach(() => PlatformTest.create());
|
|
8
|
-
afterEach(() => PlatformTest.reset());
|
|
9
|
-
|
|
10
|
-
it("should return context (no async_hook)", async () => {
|
|
11
|
-
const $ctx = PlatformTest.createRequestContext();
|
|
12
|
-
const stub = vi.fn();
|
|
13
|
-
const req = {
|
|
14
|
-
$ctx
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
await ensureContext(req, stub);
|
|
18
|
-
|
|
19
|
-
expect(stub).toHaveBeenCalledWith($ctx);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("should return context (with async_hook)", async () => {
|
|
23
|
-
const $ctx = PlatformTest.createRequestContext();
|
|
24
|
-
const stub = vi.fn();
|
|
25
|
-
const req = {};
|
|
26
|
-
|
|
27
|
-
await runInContext($ctx, () => ensureContext(req, stub));
|
|
28
|
-
|
|
29
|
-
expect(stub).toHaveBeenCalledWith($ctx);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("should return context (no async_hook, no context)", async () => {
|
|
33
|
-
const stub = vi.fn();
|
|
34
|
-
const fallback = vi.fn();
|
|
35
|
-
const req = {};
|
|
36
|
-
|
|
37
|
-
await ensureContext(req, stub, fallback);
|
|
38
|
-
|
|
39
|
-
expect(fallback).toHaveBeenCalledWith();
|
|
40
|
-
});
|
|
41
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {getContext, runInContext} from "@tsed/di";
|
|
2
|
-
|
|
3
|
-
import {PlatformContext} from "../domain/PlatformContext.js";
|
|
4
|
-
|
|
5
|
-
export function ensureContext(request: any, cb: ($ctx: PlatformContext) => any, fallback?: () => void) {
|
|
6
|
-
const $ctx = getContext<PlatformContext>();
|
|
7
|
-
|
|
8
|
-
if ($ctx) {
|
|
9
|
-
return cb($ctx);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (!request?.$ctx && fallback) {
|
|
13
|
-
return fallback();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return runInContext(request.$ctx, () => cb(request.$ctx));
|
|
17
|
-
}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import {Env} from "@tsed/core";
|
|
2
|
-
import {Configuration} from "@tsed/di";
|
|
3
|
-
|
|
4
|
-
import {getConfiguration} from "./getConfiguration.js";
|
|
5
|
-
|
|
6
|
-
class MyCtrl {}
|
|
7
|
-
|
|
8
|
-
describe("getConfiguration()", () => {
|
|
9
|
-
it("should return configuration (2)", () => {
|
|
10
|
-
@Configuration({
|
|
11
|
-
mount: {
|
|
12
|
-
"/v1": [MyCtrl]
|
|
13
|
-
}
|
|
14
|
-
})
|
|
15
|
-
class MyModule {}
|
|
16
|
-
|
|
17
|
-
expect(
|
|
18
|
-
getConfiguration(
|
|
19
|
-
{
|
|
20
|
-
mount: {
|
|
21
|
-
"/v2": [MyCtrl]
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
MyModule
|
|
25
|
-
)
|
|
26
|
-
).toEqual({
|
|
27
|
-
$$resolved: true,
|
|
28
|
-
env: "test",
|
|
29
|
-
httpPort: 8080,
|
|
30
|
-
httpsPort: false,
|
|
31
|
-
logger: {
|
|
32
|
-
debug: false,
|
|
33
|
-
jsonIndentation: 2,
|
|
34
|
-
level: "off",
|
|
35
|
-
logRequest: true
|
|
36
|
-
},
|
|
37
|
-
mount: {
|
|
38
|
-
"/v1": [MyCtrl],
|
|
39
|
-
"/v2": [MyCtrl]
|
|
40
|
-
},
|
|
41
|
-
scopes: {
|
|
42
|
-
controller: "singleton"
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
it("should load configuration for test", () => {
|
|
47
|
-
@Configuration({})
|
|
48
|
-
class App {}
|
|
49
|
-
|
|
50
|
-
const config = getConfiguration({}, App);
|
|
51
|
-
|
|
52
|
-
expect(config).toEqual({
|
|
53
|
-
$$resolved: true,
|
|
54
|
-
env: "test",
|
|
55
|
-
httpPort: 8080,
|
|
56
|
-
httpsPort: false,
|
|
57
|
-
logger: {
|
|
58
|
-
debug: false,
|
|
59
|
-
jsonIndentation: 2,
|
|
60
|
-
level: "off",
|
|
61
|
-
logRequest: true
|
|
62
|
-
},
|
|
63
|
-
mount: {},
|
|
64
|
-
scopes: {
|
|
65
|
-
controller: "singleton"
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
it("should load configuration for production", () => {
|
|
70
|
-
@Configuration({
|
|
71
|
-
env: Env.PROD
|
|
72
|
-
})
|
|
73
|
-
class App {}
|
|
74
|
-
|
|
75
|
-
const config = getConfiguration({}, App);
|
|
76
|
-
|
|
77
|
-
expect(config).toEqual({
|
|
78
|
-
$$resolved: true,
|
|
79
|
-
env: Env.PROD,
|
|
80
|
-
httpPort: 8080,
|
|
81
|
-
httpsPort: false,
|
|
82
|
-
logger: {
|
|
83
|
-
debug: false,
|
|
84
|
-
jsonIndentation: 2,
|
|
85
|
-
level: "info",
|
|
86
|
-
logRequest: true
|
|
87
|
-
},
|
|
88
|
-
mount: {},
|
|
89
|
-
scopes: {
|
|
90
|
-
controller: "singleton"
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
it("should load configuration with mount from config", () => {
|
|
95
|
-
@Configuration({
|
|
96
|
-
env: Env.PROD
|
|
97
|
-
})
|
|
98
|
-
class App {}
|
|
99
|
-
|
|
100
|
-
class Ctrl {}
|
|
101
|
-
|
|
102
|
-
const config = getConfiguration(
|
|
103
|
-
{
|
|
104
|
-
mount: {
|
|
105
|
-
"/": [Ctrl]
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
App
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
expect(config).toEqual({
|
|
112
|
-
$$resolved: true,
|
|
113
|
-
env: Env.PROD,
|
|
114
|
-
httpPort: 8080,
|
|
115
|
-
httpsPort: false,
|
|
116
|
-
logger: {
|
|
117
|
-
debug: false,
|
|
118
|
-
jsonIndentation: 2,
|
|
119
|
-
level: "info",
|
|
120
|
-
logRequest: true
|
|
121
|
-
},
|
|
122
|
-
mount: {
|
|
123
|
-
"/": [Ctrl]
|
|
124
|
-
},
|
|
125
|
-
scopes: {
|
|
126
|
-
controller: "singleton"
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
it("should load configuration with mount from decorator", () => {
|
|
131
|
-
class Ctrl {}
|
|
132
|
-
|
|
133
|
-
@Configuration({
|
|
134
|
-
env: Env.PROD,
|
|
135
|
-
mount: {
|
|
136
|
-
"/": [Ctrl]
|
|
137
|
-
}
|
|
138
|
-
})
|
|
139
|
-
class App {}
|
|
140
|
-
|
|
141
|
-
let config = getConfiguration({}, App);
|
|
142
|
-
config = getConfiguration(config, App);
|
|
143
|
-
|
|
144
|
-
expect(config).toEqual({
|
|
145
|
-
$$resolved: true,
|
|
146
|
-
env: Env.PROD,
|
|
147
|
-
httpPort: 8080,
|
|
148
|
-
httpsPort: false,
|
|
149
|
-
logger: {
|
|
150
|
-
debug: false,
|
|
151
|
-
jsonIndentation: 2,
|
|
152
|
-
level: "info",
|
|
153
|
-
logRequest: true
|
|
154
|
-
},
|
|
155
|
-
mount: {
|
|
156
|
-
"/": [Ctrl]
|
|
157
|
-
},
|
|
158
|
-
scopes: {
|
|
159
|
-
controller: "singleton"
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import {Env, Store, Type} from "@tsed/core";
|
|
2
|
-
import {mergeMount, ProviderScope, ProviderType} from "@tsed/di";
|
|
3
|
-
|
|
4
|
-
export function getConfiguration(configuration: any = {}, module: Type<any> | null = null) {
|
|
5
|
-
if (configuration.$$resolved) {
|
|
6
|
-
return configuration;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const store = module ? Store.from(module).get("configuration") || {} : {};
|
|
10
|
-
const env = configuration.env || store.env || (process.env.NODE_ENV as Env) || Env.DEV;
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
$$resolved: true,
|
|
14
|
-
env,
|
|
15
|
-
httpPort: 8080,
|
|
16
|
-
httpsPort: false,
|
|
17
|
-
...store,
|
|
18
|
-
...configuration,
|
|
19
|
-
scopes: {
|
|
20
|
-
[ProviderType.CONTROLLER]: ProviderScope.SINGLETON,
|
|
21
|
-
...store.scopes,
|
|
22
|
-
...configuration.scopes
|
|
23
|
-
},
|
|
24
|
-
mount: mergeMount(store.mount, configuration.mount),
|
|
25
|
-
logger: {
|
|
26
|
-
debug: false,
|
|
27
|
-
level: env === Env.TEST ? "off" : "info",
|
|
28
|
-
logRequest: true,
|
|
29
|
-
...store.logger,
|
|
30
|
-
...configuration.logger,
|
|
31
|
-
jsonIndentation: process.env.NODE_ENV === Env.PROD ? 0 : 2
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import {getStaticsOptions} from "./getStaticsOptions.js";
|
|
2
|
-
|
|
3
|
-
describe("getStaticsOptions()", () => {
|
|
4
|
-
it("should return the statics files options", () => {
|
|
5
|
-
const result = getStaticsOptions({
|
|
6
|
-
"/": ["/root", {root: "/root2", test: "test", hook: "$beforeRoutesInit"}]
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
expect(result).toEqual([
|
|
10
|
-
{
|
|
11
|
-
options: {
|
|
12
|
-
hook: "$afterRoutesInit",
|
|
13
|
-
root: "/root"
|
|
14
|
-
},
|
|
15
|
-
path: "/"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
options: {
|
|
19
|
-
hook: "$beforeRoutesInit",
|
|
20
|
-
root: "/root2",
|
|
21
|
-
test: "test"
|
|
22
|
-
},
|
|
23
|
-
path: "/"
|
|
24
|
-
}
|
|
25
|
-
]);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {getValue} from "@tsed/core";
|
|
2
|
-
|
|
3
|
-
import {PlatformStaticsOptions, PlatformStaticsSettings} from "../config/interfaces/PlatformStaticsSettings.js";
|
|
4
|
-
|
|
5
|
-
function mapOptions(options: any): any {
|
|
6
|
-
const opts: PlatformStaticsOptions = typeof options === "string" ? {root: options} : options;
|
|
7
|
-
return {
|
|
8
|
-
...opts,
|
|
9
|
-
hook: getValue(opts, "hook", "$afterRoutesInit")
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function getStaticsOptions(statics?: PlatformStaticsSettings): {path: string; options: PlatformStaticsOptions}[] {
|
|
14
|
-
return Object.entries(statics || {}).reduce(
|
|
15
|
-
(statics, [path, items]) => {
|
|
16
|
-
[].concat(items as any).forEach((options) => {
|
|
17
|
-
statics.push({path, options: mapOptions(options)});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
return statics;
|
|
21
|
-
},
|
|
22
|
-
[] as {path: string; options: PlatformStaticsOptions}[]
|
|
23
|
-
);
|
|
24
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type Http from "node:http";
|
|
2
|
-
import type Https from "node:https";
|
|
3
|
-
|
|
4
|
-
import {getHostInfoFromPort} from "@tsed/core";
|
|
5
|
-
import type Http2 from "http2";
|
|
6
|
-
|
|
7
|
-
export function listenServer(server: Http.Server | Https.Server | Http2.Http2Server, hostInfo: ReturnType<typeof getHostInfoFromPort>) {
|
|
8
|
-
const {address, port} = hostInfo;
|
|
9
|
-
|
|
10
|
-
const promise = new Promise((resolve, reject) => {
|
|
11
|
-
server.on("listening", resolve);
|
|
12
|
-
server.on("error", reject);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
server.listen(port, address as any);
|
|
16
|
-
|
|
17
|
-
return promise;
|
|
18
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import {mapReturnedResponse} from "../index.js";
|
|
2
|
-
|
|
3
|
-
describe("mapReturnedResponse", () => {
|
|
4
|
-
it("should map the response (1)", () => {
|
|
5
|
-
expect(
|
|
6
|
-
mapReturnedResponse({
|
|
7
|
-
description: "description",
|
|
8
|
-
type: "type",
|
|
9
|
-
collection: "collection",
|
|
10
|
-
headers: "headers"
|
|
11
|
-
})
|
|
12
|
-
).toEqual({
|
|
13
|
-
description: "description",
|
|
14
|
-
type: "type",
|
|
15
|
-
collectionType: "collection",
|
|
16
|
-
headers: "headers"
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("should map the response (2)", () => {
|
|
21
|
-
expect(
|
|
22
|
-
mapReturnedResponse({
|
|
23
|
-
description: "description",
|
|
24
|
-
use: "use",
|
|
25
|
-
collection: "collection",
|
|
26
|
-
headers: "headers"
|
|
27
|
-
})
|
|
28
|
-
).toEqual({
|
|
29
|
-
description: "description",
|
|
30
|
-
type: "use",
|
|
31
|
-
collectionType: "collection",
|
|
32
|
-
headers: "headers"
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {printRoutes} from "./printRoutes.js";
|
|
2
|
-
|
|
3
|
-
describe("printRoutes()", () => {
|
|
4
|
-
it("should return routes", () => {
|
|
5
|
-
const routes = [
|
|
6
|
-
{
|
|
7
|
-
method: "GET",
|
|
8
|
-
url: "/",
|
|
9
|
-
name: "name",
|
|
10
|
-
toJSON() {
|
|
11
|
-
return this;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
// tslint:disable-next-line: no-unused-variable
|
|
17
|
-
expect(typeof printRoutes(routes as any)).toBe("string");
|
|
18
|
-
});
|
|
19
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import {$log, colorize} from "@tsed/logger";
|
|
2
|
-
|
|
3
|
-
import {PlatformRouteDetails} from "../domain/PlatformRouteDetails.js";
|
|
4
|
-
|
|
5
|
-
export function printRoutes(routes: PlatformRouteDetails[]) {
|
|
6
|
-
const mapColor: {[key: string]: string} = {
|
|
7
|
-
GET: "green",
|
|
8
|
-
POST: "yellow",
|
|
9
|
-
PUT: "blue",
|
|
10
|
-
DELETE: "red",
|
|
11
|
-
PATCH: "magenta",
|
|
12
|
-
ALL: "cyan",
|
|
13
|
-
STATICS: "white"
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const list = routes.map((route) => {
|
|
17
|
-
const method = route.method.toUpperCase();
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
...route,
|
|
21
|
-
method: {
|
|
22
|
-
length: method.length,
|
|
23
|
-
toString: () => {
|
|
24
|
-
return colorize(method, mapColor[method]);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const str = $log.drawTable(list, {
|
|
31
|
-
padding: 1,
|
|
32
|
-
header: {
|
|
33
|
-
method: "Method",
|
|
34
|
-
url: "Endpoint",
|
|
35
|
-
name: "Class method"
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
return "\n" + str.trim();
|
|
40
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import {nameOf} from "@tsed/core";
|
|
2
|
-
|
|
3
|
-
import {Controller} from "../../../../../di/src/common/decorators/controller.js";
|
|
4
|
-
import {M1Ctrl1} from "../../../../../di/src/common/utils/__mock__/module1/controllers/M1Ctrl1.js";
|
|
5
|
-
import {Module1} from "../../../../../di/src/common/utils/__mock__/module1/Module1.js";
|
|
6
|
-
import {M2Ctrl} from "../../../../../di/src/common/utils/__mock__/module2/controllers/M2Ctrl.js";
|
|
7
|
-
import {Module2} from "../../../../../di/src/common/utils/__mock__/module2/Module2.js";
|
|
8
|
-
import {resolveControllers} from "./resolveControllers.js";
|
|
9
|
-
|
|
10
|
-
@Controller("/root")
|
|
11
|
-
class TestCtrl {}
|
|
12
|
-
|
|
13
|
-
describe("resolveControllers", () => {
|
|
14
|
-
it("should load providers and merge configuration", () => {
|
|
15
|
-
const configuration = {
|
|
16
|
-
mount: {
|
|
17
|
-
"/rest": [TestCtrl]
|
|
18
|
-
},
|
|
19
|
-
imports: [Module1, Module2]
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const result = resolveControllers(configuration);
|
|
23
|
-
const routes = result.map((item) => ({...item, token: nameOf(item.token)}));
|
|
24
|
-
|
|
25
|
-
expect(routes).toEqual([
|
|
26
|
-
{
|
|
27
|
-
route: "/m1",
|
|
28
|
-
token: "M1Ctrl1"
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
route: "/mod2",
|
|
32
|
-
token: "M2Ctrl"
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
route: "/rest",
|
|
36
|
-
token: "TestCtrl"
|
|
37
|
-
}
|
|
38
|
-
]);
|
|
39
|
-
});
|
|
40
|
-
});
|