@dooboostore/simple-boot-http-server 1.0.23 → 1.0.25
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/README.md +113 -0
- package/dist/cjs/SimpleBootHttpServer.js +80 -40
- package/dist/cjs/SimpleBootHttpServer.js.map +3 -3
- package/dist/cjs/codes/HttpHeaders.js +14 -3
- package/dist/cjs/codes/HttpHeaders.js.map +2 -2
- package/dist/cjs/codes/Mimes.js +2 -0
- package/dist/cjs/codes/Mimes.js.map +2 -2
- package/dist/cjs/decorators/MethodMapping.js +40 -9
- package/dist/cjs/decorators/MethodMapping.js.map +3 -3
- package/dist/cjs/endpoints/WebSocketEndPoint.js +16 -0
- package/dist/cjs/endpoints/WebSocketEndPoint.js.map +7 -0
- package/dist/cjs/errors/BadRequestError.js +2 -1
- package/dist/cjs/errors/BadRequestError.js.map +2 -2
- package/dist/cjs/errors/ForbiddenError.js +2 -1
- package/dist/cjs/errors/ForbiddenError.js.map +2 -2
- package/dist/cjs/errors/InternalServerError.js +2 -1
- package/dist/cjs/errors/InternalServerError.js.map +2 -2
- package/dist/cjs/errors/NotFoundError.js +2 -1
- package/dist/cjs/errors/NotFoundError.js.map +2 -2
- package/dist/cjs/errors/UnauthorizedError.js +2 -1
- package/dist/cjs/errors/UnauthorizedError.js.map +2 -2
- package/dist/cjs/filters/CacheFilter.js +75 -35
- package/dist/cjs/filters/CacheFilter.js.map +3 -3
- package/dist/cjs/filters/IntentSchemeFilter.js +97 -0
- package/dist/cjs/filters/IntentSchemeFilter.js.map +7 -0
- package/dist/cjs/filters/ResourceFilter.js +6 -2
- package/dist/cjs/filters/ResourceFilter.js.map +2 -2
- package/dist/cjs/filters/TopicProtocolFilter.js +343 -0
- package/dist/cjs/filters/TopicProtocolFilter.js.map +7 -0
- package/dist/cjs/filters/index.js +5 -1
- package/dist/cjs/filters/index.js.map +2 -2
- package/dist/cjs/index.js +30 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/inject/InjectSituationType.js +1 -1
- package/dist/cjs/inject/InjectSituationType.js.map +2 -2
- package/dist/cjs/models/RequestResponse.js +70 -91
- package/dist/cjs/models/RequestResponse.js.map +3 -3
- package/dist/cjs/models/datas/body/index.js +28 -0
- package/dist/cjs/models/datas/body/index.js.map +7 -0
- package/dist/cjs/models/datas/index.js +32 -0
- package/dist/cjs/models/datas/index.js.map +7 -0
- package/dist/cjs/models/datas/path/ReqPathData.js +29 -0
- package/dist/cjs/models/datas/path/ReqPathData.js.map +7 -0
- package/dist/cjs/models/datas/{search → path}/ReqSearchParamsObj.js.map +1 -1
- package/dist/cjs/models/datas/path/index.js +24 -0
- package/dist/cjs/models/datas/path/index.js.map +7 -0
- package/dist/cjs/models/index.js +4 -16
- package/dist/cjs/models/index.js.map +2 -2
- package/dist/cjs/models/method/index.js +22 -0
- package/dist/cjs/models/method/index.js.map +7 -0
- package/dist/cjs/models/method/patch/index.js +22 -0
- package/dist/cjs/models/method/patch/index.js.map +7 -0
- package/dist/cjs/option/HttpServerOption.js +25 -5
- package/dist/cjs/option/HttpServerOption.js.map +2 -2
- package/dist/cjs/proxy/SymbolIntentApiServiceProxy.js +144 -0
- package/dist/cjs/proxy/SymbolIntentApiServiceProxy.js.map +7 -0
- package/dist/cjs/proxy/SymbolIntentApiServiceProxyBase.js +35 -0
- package/dist/cjs/proxy/SymbolIntentApiServiceProxyBase.js.map +7 -0
- package/dist/cjs/proxy/TopicProtocolApiServiceProxy.js +324 -0
- package/dist/cjs/proxy/TopicProtocolApiServiceProxy.js.map +7 -0
- package/dist/cjs/proxy/index.js +26 -0
- package/dist/cjs/proxy/index.js.map +7 -0
- package/dist/cjs/resolvers/ResourceResolver.js +2 -2
- package/dist/cjs/resolvers/ResourceResolver.js.map +2 -2
- package/dist/cjs/session/SessionManager.js +2 -2
- package/dist/cjs/session/SessionManager.js.map +2 -2
- package/dist/cjs/websocket/WebSocketClient.js +554 -0
- package/dist/cjs/websocket/WebSocketClient.js.map +7 -0
- package/dist/cjs/websocket/WebSocketManager.js +652 -0
- package/dist/cjs/websocket/WebSocketManager.js.map +7 -0
- package/dist/cjs/websocket/index.js +24 -0
- package/dist/cjs/websocket/index.js.map +7 -0
- package/dist/esm/SimpleBootHttpServer.js +60 -20
- package/dist/esm/SimpleBootHttpServer.js.map +2 -2
- package/dist/esm/codes/HttpHeaders.js +12 -2
- package/dist/esm/codes/HttpHeaders.js.map +2 -2
- package/dist/esm/codes/Mimes.js +2 -0
- package/dist/esm/codes/Mimes.js.map +2 -2
- package/dist/esm/decorators/MethodMapping.js +24 -3
- package/dist/esm/decorators/MethodMapping.js.map +2 -2
- package/dist/esm/endpoints/WebSocketEndPoint.js +1 -0
- package/dist/esm/endpoints/WebSocketEndPoint.js.map +7 -0
- package/dist/esm/errors/BadRequestError.js +2 -1
- package/dist/esm/errors/BadRequestError.js.map +2 -2
- package/dist/esm/errors/ForbiddenError.js +2 -1
- package/dist/esm/errors/ForbiddenError.js.map +2 -2
- package/dist/esm/errors/InternalServerError.js +2 -1
- package/dist/esm/errors/InternalServerError.js.map +2 -2
- package/dist/esm/errors/NotFoundError.js +2 -1
- package/dist/esm/errors/NotFoundError.js.map +2 -2
- package/dist/esm/errors/UnauthorizedError.js +2 -1
- package/dist/esm/errors/UnauthorizedError.js.map +2 -2
- package/dist/esm/filters/CacheFilter.js +67 -27
- package/dist/esm/filters/CacheFilter.js.map +2 -2
- package/dist/esm/filters/IntentSchemeFilter.js +74 -0
- package/dist/esm/filters/IntentSchemeFilter.js.map +7 -0
- package/dist/esm/filters/ResourceFilter.js +6 -2
- package/dist/esm/filters/ResourceFilter.js.map +2 -2
- package/dist/esm/filters/TopicProtocolFilter.js +310 -0
- package/dist/esm/filters/TopicProtocolFilter.js.map +7 -0
- package/dist/esm/filters/index.js +2 -0
- package/dist/esm/filters/index.js.map +2 -2
- package/dist/esm/index.js +13 -0
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/inject/InjectSituationType.js +1 -1
- package/dist/esm/inject/InjectSituationType.js.map +2 -2
- package/dist/esm/models/RequestResponse.js +65 -86
- package/dist/esm/models/RequestResponse.js.map +2 -2
- package/dist/esm/models/datas/body/index.js +5 -0
- package/dist/esm/models/datas/body/index.js.map +7 -0
- package/dist/esm/models/datas/index.js +7 -0
- package/dist/esm/models/datas/index.js.map +7 -0
- package/dist/esm/models/datas/path/ReqPathData.js +6 -0
- package/dist/esm/models/datas/path/ReqPathData.js.map +7 -0
- package/dist/esm/models/datas/{search → path}/ReqSearchParamsObj.js.map +1 -1
- package/dist/esm/models/datas/path/index.js +3 -0
- package/dist/esm/models/datas/path/index.js.map +7 -0
- package/dist/esm/models/index.js +2 -8
- package/dist/esm/models/index.js.map +2 -2
- package/dist/esm/models/method/index.js +2 -0
- package/dist/esm/models/method/index.js.map +7 -0
- package/dist/esm/models/method/patch/index.js +2 -0
- package/dist/esm/models/method/patch/index.js.map +7 -0
- package/dist/esm/option/HttpServerOption.js +24 -4
- package/dist/esm/option/HttpServerOption.js.map +2 -2
- package/dist/esm/proxy/SymbolIntentApiServiceProxy.js +121 -0
- package/dist/esm/proxy/SymbolIntentApiServiceProxy.js.map +7 -0
- package/dist/esm/proxy/SymbolIntentApiServiceProxyBase.js +12 -0
- package/dist/esm/proxy/SymbolIntentApiServiceProxyBase.js.map +7 -0
- package/dist/esm/proxy/TopicProtocolApiServiceProxy.js +301 -0
- package/dist/esm/proxy/TopicProtocolApiServiceProxy.js.map +7 -0
- package/dist/esm/proxy/index.js +4 -0
- package/dist/esm/proxy/index.js.map +7 -0
- package/dist/esm/resolvers/ResourceResolver.js +1 -1
- package/dist/esm/resolvers/ResourceResolver.js.map +1 -1
- package/dist/esm/session/SessionManager.js +1 -1
- package/dist/esm/session/SessionManager.js.map +1 -1
- package/dist/esm/websocket/WebSocketClient.js +529 -0
- package/dist/esm/websocket/WebSocketClient.js.map +7 -0
- package/dist/esm/websocket/WebSocketManager.js +622 -0
- package/dist/esm/websocket/WebSocketManager.js.map +7 -0
- package/dist/esm/websocket/index.js +3 -0
- package/dist/esm/websocket/index.js.map +7 -0
- package/dist/esm-bundle/dooboostore-simple-boot-http-server.esm.js +18209 -5299
- package/dist/esm-bundle/dooboostore-simple-boot-http-server.esm.js.map +4 -4
- package/dist/types/SimpleBootHttpServer.d.ts +5 -3
- package/dist/types/SimpleBootHttpServer.d.ts.map +1 -1
- package/dist/types/codes/HttpHeaders.d.ts +3 -0
- package/dist/types/codes/HttpHeaders.d.ts.map +1 -1
- package/dist/types/codes/Mimes.d.ts +3 -1
- package/dist/types/codes/Mimes.d.ts.map +1 -1
- package/dist/types/decorators/MethodMapping.d.ts +13 -2
- package/dist/types/decorators/MethodMapping.d.ts.map +1 -1
- package/dist/types/endpoints/WebSocketEndPoint.d.ts +17 -0
- package/dist/types/endpoints/WebSocketEndPoint.d.ts.map +1 -0
- package/dist/types/errors/BadRequestError.d.ts +2 -2
- package/dist/types/errors/BadRequestError.d.ts.map +1 -1
- package/dist/types/errors/ForbiddenError.d.ts +2 -2
- package/dist/types/errors/ForbiddenError.d.ts.map +1 -1
- package/dist/types/errors/InternalServerError.d.ts +2 -2
- package/dist/types/errors/InternalServerError.d.ts.map +1 -1
- package/dist/types/errors/NotFoundError.d.ts +2 -2
- package/dist/types/errors/NotFoundError.d.ts.map +1 -1
- package/dist/types/errors/UnauthorizedError.d.ts +2 -2
- package/dist/types/errors/UnauthorizedError.d.ts.map +1 -1
- package/dist/types/filters/CacheFilter.d.ts +6 -0
- package/dist/types/filters/CacheFilter.d.ts.map +1 -1
- package/dist/types/filters/IntentSchemeFilter.d.ts +20 -0
- package/dist/types/filters/IntentSchemeFilter.d.ts.map +1 -0
- package/dist/types/filters/ResourceFilter.d.ts.map +1 -1
- package/dist/types/filters/TopicProtocolFilter.d.ts +34 -0
- package/dist/types/filters/TopicProtocolFilter.d.ts.map +1 -0
- package/dist/types/filters/index.d.ts +2 -0
- package/dist/types/filters/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/inject/InjectSituationType.d.ts.map +1 -1
- package/dist/types/models/RequestResponse.d.ts +12 -7
- package/dist/types/models/RequestResponse.d.ts.map +1 -1
- package/dist/types/models/datas/body/index.d.ts +5 -0
- package/dist/types/models/datas/body/index.d.ts.map +1 -0
- package/dist/types/models/datas/index.d.ts +7 -0
- package/dist/types/models/datas/index.d.ts.map +1 -0
- package/dist/types/models/datas/path/ReqPathData.d.ts +4 -0
- package/dist/types/models/datas/path/ReqPathData.d.ts.map +1 -0
- package/dist/types/models/datas/path/ReqSearchParamsObj.d.ts.map +1 -0
- package/dist/types/models/datas/path/index.d.ts +3 -0
- package/dist/types/models/datas/path/index.d.ts.map +1 -0
- package/dist/types/models/index.d.ts +2 -8
- package/dist/types/models/index.d.ts.map +1 -1
- package/dist/types/models/method/index.d.ts +2 -0
- package/dist/types/models/method/index.d.ts.map +1 -0
- package/dist/types/models/method/patch/index.d.ts +2 -0
- package/dist/types/models/method/patch/index.d.ts.map +1 -0
- package/dist/types/option/HttpServerOption.d.ts +30 -20
- package/dist/types/option/HttpServerOption.d.ts.map +1 -1
- package/dist/types/proxy/SymbolIntentApiServiceProxy.d.ts +16 -0
- package/dist/types/proxy/SymbolIntentApiServiceProxy.d.ts.map +1 -0
- package/dist/types/proxy/SymbolIntentApiServiceProxyBase.d.ts +5 -0
- package/dist/types/proxy/SymbolIntentApiServiceProxyBase.d.ts.map +1 -0
- package/dist/types/proxy/TopicProtocolApiServiceProxy.d.ts +28 -0
- package/dist/types/proxy/TopicProtocolApiServiceProxy.d.ts.map +1 -0
- package/dist/types/proxy/index.d.ts +4 -0
- package/dist/types/proxy/index.d.ts.map +1 -0
- package/dist/types/session/SessionManager.d.ts +2 -17
- package/dist/types/session/SessionManager.d.ts.map +1 -1
- package/dist/types/websocket/WebSocketClient.d.ts +88 -0
- package/dist/types/websocket/WebSocketClient.d.ts.map +1 -0
- package/dist/types/websocket/WebSocketManager.d.ts +163 -0
- package/dist/types/websocket/WebSocketManager.d.ts.map +1 -0
- package/dist/types/websocket/index.d.ts +3 -0
- package/dist/types/websocket/index.d.ts.map +1 -0
- package/dist/umd-bundle/dooboostore-simple-boot-http-server.umd.js +18108 -5198
- package/dist/umd-bundle/dooboostore-simple-boot-http-server.umd.js.map +4 -4
- package/dist/umd-bundle/websocket-client.umd.js +11374 -0
- package/dist/umd-bundle/websocket-client.umd.js.map +7 -0
- package/package.json +24 -15
- package/src/SimpleBootHttpServer.ts +367 -313
- package/src/codes/HttpHeaders.ts +13 -2
- package/src/codes/Mimes.ts +27 -25
- package/src/decorators/MethodMapping.ts +17 -4
- package/src/endpoints/WebSocketEndPoint.ts +12 -0
- package/src/errors/BadRequestError.ts +7 -3
- package/src/errors/ForbiddenError.ts +7 -3
- package/src/errors/InternalServerError.ts +7 -3
- package/src/errors/NotFoundError.ts +7 -3
- package/src/errors/UnauthorizedError.ts +7 -3
- package/src/filters/CacheFilter.ts +112 -67
- package/src/filters/IntentSchemeFilter.ts +69 -0
- package/src/filters/ResourceFilter.ts +10 -2
- package/src/filters/TopicProtocolFilter.ts +349 -0
- package/src/filters/index.ts +2 -0
- package/src/index.ts +13 -12
- package/src/inject/InjectSituationType.ts +1 -1
- package/src/models/RequestResponse.ts +136 -242
- package/src/models/datas/body/index.ts +4 -0
- package/src/models/datas/index.ts +6 -0
- package/src/models/datas/path/ReqPathData.ts +3 -0
- package/src/models/datas/path/index.ts +2 -0
- package/src/models/index.ts +2 -8
- package/src/models/method/index.ts +1 -0
- package/src/models/method/patch/index.ts +1 -0
- package/src/option/HttpServerOption.ts +73 -23
- package/src/proxy/SymbolIntentApiServiceProxy.ts +126 -0
- package/src/proxy/SymbolIntentApiServiceProxyBase.ts +16 -0
- package/src/proxy/TopicProtocolApiServiceProxy.ts +328 -0
- package/src/proxy/index.ts +3 -0
- package/src/resolvers/ResourceResolver.ts +1 -1
- package/src/session/SessionManager.ts +3 -3
- package/src/websocket/WebSocketClient.ts +637 -0
- package/src/websocket/WebSocketManager.ts +713 -0
- package/src/websocket/index.ts +2 -0
- package/tsconfig.json +3 -1
- package/README.MD +0 -36
- package/dist/types/models/datas/search/ReqSearchParamsObj.d.ts.map +0 -1
- /package/dist/cjs/models/datas/{search → path}/ReqSearchParamsObj.js +0 -0
- /package/dist/esm/models/datas/{search → path}/ReqSearchParamsObj.js +0 -0
- /package/dist/types/models/datas/{search → path}/ReqSearchParamsObj.d.ts +0 -0
- /package/src/models/datas/{search → path}/ReqSearchParamsObj.ts +0 -0
|
@@ -1,346 +1,400 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
1
|
+
import {SimpleApplication} from '@dooboostore/simple-boot';
|
|
2
|
+
import {HttpServerOption} from './option/HttpServerOption';
|
|
3
|
+
import {ConstructorType} from '@dooboostore/core';
|
|
4
|
+
import {IncomingMessage, Server as HttpServer, ServerResponse} from 'http'
|
|
5
|
+
import {Server as HttpsServer} from 'https'; // Add HTTPS support
|
|
6
|
+
import {WebSocketServer, WebSocket} from 'ws';
|
|
7
|
+
import {RequestResponse} from './models/RequestResponse';
|
|
8
|
+
import {getUrlMapping, getUrlMappings, SaveMappingConfig, UrlMappingSituationType} from './decorators/MethodMapping';
|
|
9
|
+
import {HttpStatus} from './codes/HttpStatus';
|
|
10
|
+
import {HttpHeaders} from './codes/HttpHeaders';
|
|
11
|
+
import {Mimes} from './codes/Mimes';
|
|
12
|
+
import {Filter} from './filters/Filter';
|
|
13
|
+
import {ExceptionHandlerSituationType, targetExceptionHandler} from '@dooboostore/simple-boot';
|
|
14
|
+
import {getInject, SituationTypeContainer, SituationTypeContainers} from '@dooboostore/simple-boot';
|
|
15
|
+
import {EndPoint} from './endpoints/EndPoint';
|
|
16
|
+
import {ReflectUtils} from '@dooboostore/core';
|
|
17
|
+
import {ReqFormUrlBody} from './models/datas/body/ReqFormUrlBody';
|
|
18
|
+
import {ReqJsonBody} from './models/datas/body/ReqJsonBody';
|
|
19
|
+
import {ReqHeader} from './models/datas/ReqHeader';
|
|
20
|
+
import {RouterModule} from '@dooboostore/simple-boot';
|
|
21
|
+
import {ReqMultipartFormBody} from './models/datas/body/ReqMultipartFormBody';
|
|
22
|
+
import {execValidationInValid, getValidIndex} from '@dooboostore/simple-boot';
|
|
23
|
+
import {ValidException} from '@dooboostore/simple-boot';
|
|
24
|
+
import {HttpError} from './errors/HttpError';
|
|
25
|
+
import {getRoute} from '@dooboostore/simple-boot';
|
|
26
|
+
import {OnInit} from './lifecycle/OnInit';
|
|
27
|
+
import {URLSearchParams} from 'url';
|
|
28
|
+
import {HttpMethod} from './codes/HttpMethod';
|
|
29
|
+
import {SessionManager} from './session/SessionManager';
|
|
30
|
+
import {InjectSituationType} from './inject/InjectSituationType';
|
|
31
|
+
import {ReqSearchParamsObj} from "./models/datas/path/ReqSearchParamsObj";
|
|
32
|
+
import {SimConfig} from '@dooboostore/simple-boot';
|
|
33
|
+
import {ReqPathData} from './models/datas/path/ReqPathData';
|
|
34
|
+
import {WebSocketEndPoint} from './endpoints/WebSocketEndPoint';
|
|
31
35
|
|
|
32
36
|
export class SimpleBootHttpServer extends SimpleApplication {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
super(option);
|
|
37
|
-
this.sessionManager = new SessionManager(this.option);
|
|
38
|
-
}
|
|
39
|
-
|
|
37
|
+
public server?: HttpServer | HttpsServer;
|
|
38
|
+
private sessionManager: SessionManager;
|
|
39
|
+
private webSocketClients = new Map<WebSocket, { request: IncomingMessage }>();
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.startServer();
|
|
46
|
-
});
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
41
|
+
constructor(public option: HttpServerOption = new HttpServerOption()) {
|
|
42
|
+
super(option);
|
|
43
|
+
this.sessionManager = new SessionManager(this.option);
|
|
44
|
+
}
|
|
49
45
|
|
|
50
|
-
private startServer() {
|
|
51
46
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
httpServer.listen(80, this.option.listen.hostname, () => {
|
|
63
|
-
console.log('HTTP redirect server running on port 80');
|
|
64
|
-
});
|
|
65
|
-
} else if (this.option.serverOption) {
|
|
66
|
-
this.server = new HttpServer(this.option.serverOption);
|
|
67
|
-
} else {
|
|
68
|
-
this.server = new HttpServer();
|
|
69
|
-
}
|
|
70
|
-
// const thisRef = this;
|
|
71
|
-
this.server.on('request', async (req: IncomingMessage, res: ServerResponse) => {
|
|
72
|
-
// console.log('request', req.url);
|
|
73
|
-
const transactionManager = this.option.transactionManagerFactory ? await this.option.transactionManagerFactory() : undefined;
|
|
74
|
-
res.on('close', async () => {
|
|
75
|
-
if (this.option.closeEndPoints) {
|
|
76
|
-
for (const it of this.option.closeEndPoints) {
|
|
77
|
-
try {
|
|
78
|
-
const execute = (typeof it === 'function' ? this.simstanceManager.getOrNewSim({target:it}) : it) as EndPoint;
|
|
79
|
-
const endPoint = execute?.endPoint(rr, this);
|
|
80
|
-
if (endPoint instanceof Promise) {
|
|
81
|
-
await endPoint;
|
|
82
|
-
}
|
|
83
|
-
} catch (e) {
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
47
|
+
public run(otherInstanceSim?: Map<ConstructorType<any> | Function | SimConfig | symbol, any>) {
|
|
48
|
+
otherInstanceSim ??= new Map<ConstructorType<any> | Function | SimConfig | symbol, any>();
|
|
49
|
+
otherInstanceSim.set(SimpleBootHttpServer, this);
|
|
50
|
+
super.run(otherInstanceSim);
|
|
51
|
+
const targets = [...this.option.closeEndPoints ?? [], ...this.option.errorEndPoints ?? [], ...this.option.requestEndPoints ?? [], ...this.option.filters ?? []];
|
|
52
|
+
Promise.all(targets.map(it => (typeof it === 'function' ? this.simstanceManager.getOrNewSim({target: it as ConstructorType<any>}) : it) as OnInit).map(it => it.onInit(this))).then(it => {
|
|
53
|
+
this.startServer();
|
|
54
|
+
});
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
87
57
|
|
|
88
|
-
|
|
89
|
-
rr.resEnd();
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
res.on('error', async () => {
|
|
93
|
-
if (this.option.errorEndPoints) {
|
|
94
|
-
for (const it of this.option.errorEndPoints) {
|
|
95
|
-
try {
|
|
96
|
-
const execute = (typeof it === 'function' ? this.simstanceManager.getOrNewSim({target:it}) : it) as EndPoint;
|
|
97
|
-
const endPoint = execute?.endPoint(rr, this);
|
|
98
|
-
if (endPoint instanceof Promise) {
|
|
99
|
-
await endPoint;
|
|
100
|
-
}
|
|
101
|
-
} catch (e) {
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
58
|
+
private startServer() {
|
|
105
59
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
});
|
|
60
|
+
// const a = this.option.serverOption as HttpsServerOption;
|
|
61
|
+
// this.option.serverOption?.
|
|
110
62
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
63
|
+
if (this.option.serverOption && 'key' in this.option.serverOption && 'cert' in this.option.serverOption) {
|
|
64
|
+
this.server = new HttpsServer(this.option.serverOption);
|
|
65
|
+
const httpServer = new HttpServer();
|
|
66
|
+
httpServer.on('request', (req: IncomingMessage, res: ServerResponse) => {
|
|
67
|
+
res.writeHead(301, {Location: `https://${req.headers.host}${req.url}`});
|
|
68
|
+
res.end();
|
|
69
|
+
});
|
|
70
|
+
httpServer.listen(80, this.option.listen.hostname, () => {
|
|
71
|
+
console.log('HTTP redirect server running on port 80');
|
|
72
|
+
});
|
|
73
|
+
} else if (this.option.serverOption) {
|
|
74
|
+
this.server = new HttpServer(this.option.serverOption);
|
|
75
|
+
} else {
|
|
76
|
+
this.server = new HttpServer();
|
|
77
|
+
}
|
|
78
|
+
// const thisRef = this;
|
|
79
|
+
this.server.on('request', async (req: IncomingMessage, res: ServerResponse) => {
|
|
80
|
+
// console.log('request', req.url);
|
|
81
|
+
const transactionManager = this.option.transactionManagerFactory ? await this.option.transactionManagerFactory() : undefined;
|
|
82
|
+
res.on('close', async () => {
|
|
83
|
+
if (this.option.closeEndPoints) {
|
|
84
|
+
for (const it of this.option.closeEndPoints) {
|
|
85
|
+
try {
|
|
86
|
+
const execute = (typeof it === 'function' ? this.simstanceManager.getOrNewSim({target: it}) : it) as EndPoint;
|
|
87
|
+
const endPoint = execute?.endPoint(rr, this);
|
|
88
|
+
if (endPoint instanceof Promise) {
|
|
89
|
+
await endPoint;
|
|
90
|
+
}
|
|
91
|
+
} catch (e) {
|
|
120
92
|
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
121
95
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
96
|
+
if (!rr.resIsDone()) {
|
|
97
|
+
rr.resEnd();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
res.on('error', async () => {
|
|
101
|
+
if (this.option.errorEndPoints) {
|
|
102
|
+
for (const it of this.option.errorEndPoints) {
|
|
126
103
|
try {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
104
|
+
const execute = (typeof it === 'function' ? this.simstanceManager.getOrNewSim({target: it}) : it) as EndPoint;
|
|
105
|
+
const endPoint = execute?.endPoint(rr, this);
|
|
106
|
+
if (endPoint instanceof Promise) {
|
|
107
|
+
await endPoint;
|
|
108
|
+
}
|
|
109
|
+
} catch (e) {
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
137
113
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
for (let i = 0; this.option.filters && i < this.option.filters.length; i++) {
|
|
143
|
-
const it = this.option.filters[i];
|
|
144
|
-
const execute = (typeof it === 'function' ? this.simstanceManager.getOrNewSim({target:it}) : it) as Filter;
|
|
145
|
-
let sw = true;
|
|
146
|
-
if (execute?.proceedBefore) {
|
|
147
|
-
sw = await execute.proceedBefore({rr, app: this, carrier: filter.carrier});
|
|
148
|
-
filter.filters.push({filter: execute, sw});
|
|
149
|
-
}
|
|
150
|
-
if (!sw) {
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
114
|
+
if (!rr.resIsDone()) {
|
|
115
|
+
rr.resEnd();
|
|
116
|
+
}
|
|
117
|
+
});
|
|
154
118
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (routerModule.propertyKeys) {
|
|
164
|
-
const map = routerModule.propertyKeys?.map((it: string | symbol) => {
|
|
165
|
-
return {propertyKey: it, config: getUrlMapping(moduleInstance, it)} as SaveMappingConfig
|
|
166
|
-
});
|
|
167
|
-
methods.push(...(map ?? []));
|
|
168
|
-
} else {
|
|
169
|
-
methods.push(...(getUrlMappings(moduleInstance).filter(it => !getRoute(moduleInstance, it.propertyKey)) ?? []));
|
|
170
|
-
}
|
|
119
|
+
const rr = new RequestResponse(req, res, {sessionManager: this.sessionManager, option: this.option});
|
|
120
|
+
/*
|
|
121
|
+
default setting first
|
|
122
|
+
*/
|
|
123
|
+
rr.resSetHeader(HttpHeaders.Server, 'simple-boot-http-server');
|
|
124
|
+
const cookie = rr.reqCookieGet(this.option.sessionOption.key);
|
|
125
|
+
if (!cookie) {
|
|
126
|
+
const session = await this.sessionManager.session();
|
|
171
127
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
128
|
+
const cookieParts: string[] = [];
|
|
129
|
+
cookieParts.push(`${this.option.sessionOption.key}=${session.uuid}`);
|
|
130
|
+
cookieParts.push(`Path=${this.option.sessionOption.path}`);
|
|
131
|
+
if (this.option.sessionOption.httpOnly) cookieParts.push('HttpOnly');
|
|
132
|
+
if (this.option.sessionOption.secure) cookieParts.push('Secure');
|
|
133
|
+
if (this.option.sessionOption.sameSite != null && this.option.sessionOption.sameSite) cookieParts.push(`SameSite=${this.option.sessionOption.sameSite}`);
|
|
134
|
+
const maxAge = (this.option.sessionOption as any).maxAge ?? (this.sessionManager.sessionOption)?.maxAge;
|
|
135
|
+
if (maxAge != null) cookieParts.push(`Max-Age=${maxAge}`);
|
|
136
|
+
rr.resSetHeader(HttpHeaders.SetCookie, cookieParts.join('; '));
|
|
137
|
+
}
|
|
177
138
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
139
|
+
const otherStorage = new Map<ConstructorType<any>, any>();
|
|
140
|
+
otherStorage.set(RequestResponse, rr);
|
|
141
|
+
otherStorage.set(IncomingMessage, req);
|
|
142
|
+
otherStorage.set(ServerResponse, res);
|
|
143
|
+
try {
|
|
144
|
+
transactionManager?.try();
|
|
145
|
+
if (this.option.requestEndPoints) {
|
|
146
|
+
for (const it of this.option.requestEndPoints) {
|
|
147
|
+
try {
|
|
148
|
+
const execute = (typeof it === 'function' ? this.simstanceManager.getOrNewSim<EndPoint>({target: it}) : it) as EndPoint;
|
|
149
|
+
execute?.endPoint(rr, this);
|
|
150
|
+
} catch (e) {
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
186
154
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
if (validIndexs.includes(isJson.index)) {
|
|
204
|
-
const inValid = execValidationInValid(data);
|
|
205
|
-
if ((inValid?.length ?? 0) > 0) {
|
|
206
|
-
throw new ValidException(inValid);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
siturationContainers.push(new SituationTypeContainer({
|
|
210
|
-
situationType: UrlMappingSituationType.REQ_JSON_BODY,
|
|
211
|
-
data
|
|
212
|
-
}));
|
|
213
|
-
}
|
|
214
|
-
if (isSearchParamsObj) {
|
|
215
|
-
let data = rr.reqUrlSearchParamsObj
|
|
216
|
-
if (validIndexs.includes(isSearchParamsObj.index)) {
|
|
217
|
-
const inValid = execValidationInValid(data);
|
|
218
|
-
if ((inValid?.length ?? 0) > 0) {
|
|
219
|
-
throw new ValidException(inValid);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
siturationContainers.push(new SituationTypeContainer({
|
|
223
|
-
situationType: UrlMappingSituationType.REQ_URL_SEARCH_PARAMS_OBJ,
|
|
224
|
-
data
|
|
225
|
-
}));
|
|
226
|
-
}
|
|
227
|
-
if (isFormUrl) {
|
|
228
|
-
let data = await rr.reqBodyFormUrlData()
|
|
229
|
-
if (isFormUrl.type) {
|
|
230
|
-
data = Object.assign(new isFormUrl.type(), data);
|
|
231
|
-
}
|
|
232
|
-
if (validIndexs.includes(isFormUrl.index)) {
|
|
233
|
-
const inValid = execValidationInValid(data);
|
|
234
|
-
if ((inValid?.length ?? 0) > 0) {
|
|
235
|
-
throw new ValidException(inValid);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
siturationContainers.push(new SituationTypeContainer({situationType: UrlMappingSituationType.REQ_FORM_URL_BODY, data}));
|
|
239
|
-
}
|
|
155
|
+
const filter = {
|
|
156
|
+
carrier: new Map<string, any>(),
|
|
157
|
+
filters: [] as { filter: Filter, sw: boolean }[]
|
|
158
|
+
};
|
|
159
|
+
for (let i = 0; this.option.filters && i < this.option.filters.length; i++) {
|
|
160
|
+
const it = this.option.filters[i];
|
|
161
|
+
const execute = (typeof it === 'function' ? this.simstanceManager.getOrNewSim({target: it}) : it) as Filter;
|
|
162
|
+
let sw = true;
|
|
163
|
+
if (execute?.proceedBefore) {
|
|
164
|
+
sw = await execute.proceedBefore({rr, app: this, carrier: filter.carrier});
|
|
165
|
+
filter.filters.push({filter: execute, sw});
|
|
166
|
+
}
|
|
167
|
+
if (!sw) {
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
240
171
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
172
|
+
// body.. something..
|
|
173
|
+
if (!rr.resIsDone()) {
|
|
174
|
+
const routerModule = await super.routing(rr.reqIntent);
|
|
175
|
+
otherStorage.set(RouterModule, routerModule);
|
|
176
|
+
const moduleInstance = routerModule?.getModuleInstance?.();
|
|
177
|
+
let methods: SaveMappingConfig[] = [];
|
|
178
|
+
if (routerModule && moduleInstance) {
|
|
179
|
+
// router 클래스 내부에서 선언된 Route일때
|
|
180
|
+
if (routerModule.propertyKeys) {
|
|
181
|
+
const map = routerModule.propertyKeys?.map((it: string | symbol) => {
|
|
182
|
+
return {propertyKey: it, config: getUrlMapping(moduleInstance, it)} as SaveMappingConfig
|
|
183
|
+
});
|
|
184
|
+
methods.push(...(map ?? []));
|
|
185
|
+
} else {
|
|
186
|
+
methods.push(...(getUrlMappings(moduleInstance).filter(it => !getRoute(moduleInstance, it.propertyKey)) ?? []));
|
|
187
|
+
}
|
|
252
188
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
} else if (paramType === ReqSearchParamsObj) {
|
|
259
|
-
otherStorage.set(ReqSearchParamsObj, rr.reqUrlSearchParamsObj)
|
|
260
|
-
}else if (paramType === URLSearchParams) {
|
|
261
|
-
otherStorage.set(URLSearchParams, rr.reqUrlSearchParams)
|
|
262
|
-
} else if (paramType === ReqMultipartFormBody) {
|
|
263
|
-
otherStorage.set(ReqMultipartFormBody, rr.reqBodyMultipartFormData())
|
|
264
|
-
} else if (paramType === ReqHeader) {
|
|
265
|
-
otherStorage.set(ReqHeader, rr.reqHeaderObj)
|
|
266
|
-
}
|
|
267
|
-
}
|
|
189
|
+
// options로 요청오면은 allow로 넣고 그냥 200처리해야됨.
|
|
190
|
+
if (rr.reqMethod()?.toUpperCase() === HttpMethod.OPTIONS.toUpperCase()) {
|
|
191
|
+
rr.resSetHeader(HttpHeaders.Allow, methods.map(it => it.config.method).join(', '));
|
|
192
|
+
rr.resStatusCode(HttpStatus.Ok);
|
|
193
|
+
}
|
|
268
194
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
*/
|
|
278
|
-
if (it.config?.resolver) {
|
|
279
|
-
const execute = typeof it.config.resolver === 'function' ? this.simstanceManager.getOrNewSim({target:it.config.resolver}) : it.config.resolver;
|
|
280
|
-
data = await execute?.resolve?.(data, rr);
|
|
281
|
-
}
|
|
282
|
-
const status = it.config?.res?.status ?? HttpStatus.Ok;
|
|
283
|
-
const headers = it.config?.res?.header ?? {};
|
|
284
|
-
if (it.config?.res?.contentType) {
|
|
285
|
-
headers[HttpHeaders.ContentType] = it.config?.res?.contentType;
|
|
286
|
-
}
|
|
287
|
-
if ((it.config?.res?.contentType?.toLowerCase().indexOf(Mimes.ApplicationJson.toLowerCase()) ?? -1) > -1) {
|
|
288
|
-
data = JSON.stringify(data);
|
|
289
|
-
} else if (data && typeof data === 'object') {
|
|
290
|
-
data = JSON.stringify(data);
|
|
291
|
-
}
|
|
292
|
-
rr.resSetHeaders(headers)
|
|
293
|
-
rr.resSetStatusCode(status);
|
|
294
|
-
rr.resWrite(data);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
195
|
+
// method 찾기
|
|
196
|
+
methods = methods.filter(it => it && it.propertyKey && it.config && rr.reqMethod()?.toUpperCase() === it.config.method.toUpperCase());
|
|
197
|
+
methods.sort((a, b) => {
|
|
198
|
+
return ((b.config?.req?.contentType?.length ?? 0) + (b.config?.req?.accept?.length ?? 0)) - ((a.config?.req?.contentType?.length ?? 0) + (a.config?.req?.accept?.length ?? 0));
|
|
199
|
+
});
|
|
200
|
+
methods = methods
|
|
201
|
+
.filter(it => it.config?.req?.contentType ? (!!it.config?.req?.contentType?.find(sit => rr.reqHasContentTypeHeader(sit))) : true)
|
|
202
|
+
.filter(it => it.config?.req?.accept ? (!!it.config?.req?.accept?.find(sit => rr.reqHasAcceptHeader(sit))) : true);
|
|
297
203
|
|
|
298
|
-
|
|
299
|
-
|
|
204
|
+
if (methods[0]) {
|
|
205
|
+
const it = methods[0];
|
|
206
|
+
const paramTypes = ReflectUtils.getParameterTypes(moduleInstance, it.propertyKey)
|
|
207
|
+
const injects = getInject(moduleInstance, it.propertyKey);
|
|
208
|
+
const validIndexs = getValidIndex(moduleInstance, it.propertyKey);
|
|
209
|
+
if (injects) {
|
|
210
|
+
const isPathData = injects.find(it => it.config?.situationType === UrlMappingSituationType.REQ_PATH_DATA);
|
|
211
|
+
const isJson = injects.find(it => it.config?.situationType === UrlMappingSituationType.REQ_JSON_BODY);
|
|
212
|
+
const isSearchParamsObj = injects.find(it => it.config?.situationType === UrlMappingSituationType.REQ_URL_SEARCH_PARAMS_OBJ);
|
|
213
|
+
const isFormUrl = injects.find(it => it.config?.situationType === UrlMappingSituationType.REQ_FORM_URL_BODY);
|
|
214
|
+
// 우선 다시 제거한다.. 트랜젝션 어떻게 할지 다시 생각
|
|
215
|
+
// const isTransactionManager = injects.find(it => it.config?.situationType === InjectSituationType.TransactionManager);
|
|
216
|
+
const siturationContainers = new SituationTypeContainers();
|
|
217
|
+
if (isPathData) {
|
|
218
|
+
let data = await routerModule.pathData
|
|
219
|
+
if (isPathData.type) {
|
|
220
|
+
data = Object.assign(new isPathData.type(), data);
|
|
221
|
+
}
|
|
222
|
+
if (validIndexs.includes(isPathData.index)) {
|
|
223
|
+
const inValid = execValidationInValid(data);
|
|
224
|
+
if ((inValid?.length ?? 0) > 0) {
|
|
225
|
+
throw new ValidException(inValid);
|
|
300
226
|
}
|
|
227
|
+
}
|
|
228
|
+
siturationContainers.push(new SituationTypeContainer({
|
|
229
|
+
situationType: UrlMappingSituationType.REQ_PATH_DATA,
|
|
230
|
+
data
|
|
231
|
+
}));
|
|
301
232
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
233
|
+
if (isJson) {
|
|
234
|
+
let data = await rr.reqBodyJsonData();
|
|
235
|
+
if (data !== null && isJson.type) {
|
|
236
|
+
data = Object.assign(new isJson.type(), data);
|
|
237
|
+
}
|
|
238
|
+
if (validIndexs.includes(isJson.index)) {
|
|
239
|
+
const inValid = execValidationInValid(data);
|
|
240
|
+
if ((inValid?.length ?? 0) > 0) {
|
|
241
|
+
throw new ValidException(inValid);
|
|
307
242
|
}
|
|
243
|
+
}
|
|
244
|
+
siturationContainers.push(new SituationTypeContainer({
|
|
245
|
+
situationType: UrlMappingSituationType.REQ_JSON_BODY,
|
|
246
|
+
data
|
|
247
|
+
}));
|
|
308
248
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
249
|
+
if (isSearchParamsObj) {
|
|
250
|
+
let data = rr.reqUrlSearchParamsObj
|
|
251
|
+
if (validIndexs.includes(isSearchParamsObj.index)) {
|
|
252
|
+
const inValid = execValidationInValid(data);
|
|
253
|
+
if ((inValid?.length ?? 0) > 0) {
|
|
254
|
+
throw new ValidException(inValid);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
siturationContainers.push(new SituationTypeContainer({
|
|
258
|
+
situationType: UrlMappingSituationType.REQ_URL_SEARCH_PARAMS_OBJ,
|
|
259
|
+
data
|
|
260
|
+
}));
|
|
318
261
|
}
|
|
319
|
-
if (
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
262
|
+
if (isFormUrl) {
|
|
263
|
+
let data = await rr.reqBodyFormUrlData()
|
|
264
|
+
if (isFormUrl.type) {
|
|
265
|
+
data = Object.assign(new isFormUrl.type(), data);
|
|
266
|
+
}
|
|
267
|
+
if (validIndexs.includes(isFormUrl.index)) {
|
|
268
|
+
const inValid = execValidationInValid(data);
|
|
269
|
+
if ((inValid?.length ?? 0) > 0) {
|
|
270
|
+
throw new ValidException(inValid);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
siturationContainers.push(new SituationTypeContainer({situationType: UrlMappingSituationType.REQ_FORM_URL_BODY, data}));
|
|
325
274
|
}
|
|
326
|
-
|
|
327
|
-
if (
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
275
|
+
// 트랜젝션 우선 제거 나중에 어떻게 구현할지 생각..
|
|
276
|
+
// if (isTransactionManager && isTransactionManager.type && transactionManager && transactionManager.hasTransaction(isTransactionManager.type)) {
|
|
277
|
+
// let data = await transactionManager.getTransaction(isTransactionManager.type);
|
|
278
|
+
// if (data) {
|
|
279
|
+
// data = await data.try(isTransactionManager.config.argument);
|
|
280
|
+
// siturationContainers.push(new SituationTypeContainer({situationType: InjectSituationType.TransactionManager, data, index: isTransactionManager.index}));
|
|
281
|
+
// }
|
|
282
|
+
// }
|
|
283
|
+
if (siturationContainers.length) {
|
|
284
|
+
otherStorage.set(SituationTypeContainers, siturationContainers);
|
|
332
285
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
for (const paramType of paramTypes) {
|
|
289
|
+
if (paramType === ReqFormUrlBody) {
|
|
290
|
+
otherStorage.set(ReqFormUrlBody, await rr.reqBodyReqFormUrlBody())
|
|
291
|
+
} else if (paramType === ReqPathData) {
|
|
292
|
+
otherStorage.set(ReqPathData, routerModule.pathData)
|
|
293
|
+
} else if (paramType === ReqJsonBody) {
|
|
294
|
+
otherStorage.set(ReqJsonBody, await rr.reqBodyReqJsonBody())
|
|
295
|
+
} else if (paramType === ReqSearchParamsObj) {
|
|
296
|
+
otherStorage.set(ReqSearchParamsObj, rr.reqUrlSearchParamsObj)
|
|
297
|
+
} else if (paramType === URLSearchParams) {
|
|
298
|
+
otherStorage.set(URLSearchParams, rr.reqUrlSearchParams)
|
|
299
|
+
} else if (paramType === ReqMultipartFormBody) {
|
|
300
|
+
otherStorage.set(ReqMultipartFormBody, rr.reqBodyMultipartFormData())
|
|
301
|
+
} else if (paramType === ReqHeader) {
|
|
302
|
+
otherStorage.set(ReqHeader, rr.reqHeaderObj)
|
|
303
|
+
}
|
|
304
|
+
}
|
|
336
305
|
|
|
337
|
-
|
|
338
|
-
|
|
306
|
+
// execute !!!
|
|
307
|
+
let data = await this.simstanceManager.executeBindParameterSimPromise({
|
|
308
|
+
target: moduleInstance,
|
|
309
|
+
targetKey: it.propertyKey
|
|
310
|
+
}, otherStorage);
|
|
311
|
+
/*
|
|
312
|
+
여기에서 정해진 타입 리턴에 따른 조치
|
|
313
|
+
...
|
|
314
|
+
*/
|
|
315
|
+
if (it.config?.resolver) {
|
|
316
|
+
const execute = typeof it.config.resolver === 'function' ? this.simstanceManager.getOrNewSim({target: it.config.resolver}) : it.config.resolver;
|
|
317
|
+
data = await execute?.resolve?.(data, rr);
|
|
318
|
+
}
|
|
319
|
+
const status = it.config?.res?.status ?? HttpStatus.Ok;
|
|
320
|
+
const headers = it.config?.res?.header ?? {};
|
|
321
|
+
if (it.config?.res?.contentType) {
|
|
322
|
+
headers[HttpHeaders.ContentType] = it.config?.res?.contentType;
|
|
323
|
+
}
|
|
324
|
+
if ((it.config?.res?.contentType?.toLowerCase().indexOf(Mimes.ApplicationJson.toLowerCase()) ?? -1) > -1) {
|
|
325
|
+
data = JSON.stringify(data);
|
|
326
|
+
} else if (data && typeof data === 'object') {
|
|
327
|
+
data = JSON.stringify(data);
|
|
328
|
+
}
|
|
329
|
+
rr.resSetHeaders(headers)
|
|
330
|
+
rr.resSetStatusCode(status);
|
|
331
|
+
rr.resWrite(data);
|
|
339
332
|
}
|
|
340
|
-
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (this.option.noSuchRouteEndPointMappingThrow && methods.length <= 0 && rr.reqMethod()?.toUpperCase() !== HttpMethod.OPTIONS) {
|
|
336
|
+
throw this.option.noSuchRouteEndPointMappingThrow(rr);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// after
|
|
341
|
+
for (const it of filter.filters.reverse()) {
|
|
342
|
+
if (it.filter?.proceedAfter && !await it.filter.proceedAfter({rr, app: this, before: it.sw, carrier: filter.carrier})) {
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
} catch (e) {
|
|
347
|
+
console.error('request error:', e);
|
|
348
|
+
transactionManager?.catch(e);
|
|
349
|
+
rr.resStatusCode(e instanceof HttpError ? e.status : HttpStatus.InternalServerError)
|
|
350
|
+
const execute = typeof this.option.globalAdvice === 'function' ? this.simstanceManager.getOrNewSim(this.option.globalAdvice) : this.option.globalAdvice;
|
|
351
|
+
if (!execute) {
|
|
352
|
+
rr.resEnd();
|
|
353
|
+
// rr.resEnd().catch(e => {
|
|
354
|
+
// });
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (e && typeof e === 'object') {
|
|
358
|
+
otherStorage.set(e.constructor as ConstructorType<any>, e);
|
|
359
|
+
otherStorage.set(SituationTypeContainer, new SituationTypeContainer({
|
|
360
|
+
situationType: ExceptionHandlerSituationType.ERROR_OBJECT,
|
|
361
|
+
data: e
|
|
362
|
+
}));
|
|
363
|
+
}
|
|
364
|
+
const target = targetExceptionHandler(execute, e);
|
|
365
|
+
if (target) {
|
|
366
|
+
await this.simstanceManager.executeBindParameterSimPromise({
|
|
367
|
+
target: execute,
|
|
368
|
+
targetKey: target.propertyKey
|
|
369
|
+
}, otherStorage);
|
|
370
|
+
}
|
|
371
|
+
} finally {
|
|
372
|
+
transactionManager?.finally();
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (!rr.resIsDone()) {
|
|
376
|
+
rr.resEnd();
|
|
377
|
+
}
|
|
378
|
+
});
|
|
341
379
|
|
|
342
|
-
|
|
343
|
-
|
|
380
|
+
if (this.option.webSocketEndPoints) {
|
|
381
|
+
const webSocketServer = new WebSocketServer({server: this.server});
|
|
382
|
+
const execute = this.option.webSocketEndPoints.map(it => typeof it === 'function' ? this.simstanceManager.getOrNewSim({target: it}) : it);
|
|
383
|
+
webSocketServer.on('connection', async (ws, request) => {
|
|
384
|
+
this.webSocketClients.set(ws, {request});
|
|
385
|
+
const wsSet = {socket: ws, request};
|
|
386
|
+
execute.forEach(it => it.connect?.(wsSet));
|
|
387
|
+
ws.on('error', err => execute.forEach(it => it.error?.(wsSet, err)));
|
|
388
|
+
ws.on('message', (data, isBinary) => execute.forEach(it => it.message(wsSet, {data, isBinary})));
|
|
389
|
+
ws.on('ping', () => execute.forEach(it => it.ping?.(wsSet)));
|
|
390
|
+
ws.on('close', () => {
|
|
391
|
+
this.webSocketClients.delete(ws);
|
|
392
|
+
execute.forEach(it => it.close?.(wsSet));
|
|
344
393
|
});
|
|
394
|
+
});
|
|
345
395
|
}
|
|
396
|
+
this.server.listen(this.option.listen.port, this.option.listen.hostname, this.option.listen.backlog, () => {
|
|
397
|
+
this.option.listen.listeningListener?.(this, this.server);
|
|
398
|
+
});
|
|
399
|
+
}
|
|
346
400
|
}
|