@dooboostore/simple-boot-http-server 1.0.18 → 1.0.19
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/dist/cjs/SimpleBootHttpServer.d.ts +2 -1
- package/dist/cjs/SimpleBootHttpServer.d.ts.map +1 -1
- package/dist/cjs/SimpleBootHttpServer.js +53 -673
- package/dist/cjs/SimpleBootHttpServer.js.map +4 -4
- package/dist/cjs/codes/HttpHeaders.js +0 -2
- package/dist/cjs/codes/HttpHeaders.js.map +1 -1
- package/dist/cjs/codes/HttpMethod.js +0 -2
- package/dist/cjs/codes/HttpMethod.js.map +1 -1
- package/dist/cjs/codes/HttpStatus.js +0 -2
- package/dist/cjs/codes/HttpStatus.js.map +1 -1
- package/dist/cjs/codes/Mimes.js +0 -2
- package/dist/cjs/codes/Mimes.js.map +1 -1
- package/dist/cjs/codes/index.js +9 -126
- package/dist/cjs/codes/index.js.map +4 -4
- package/dist/cjs/decorators/MethodMapping.d.ts +0 -1
- package/dist/cjs/decorators/MethodMapping.d.ts.map +1 -1
- package/dist/cjs/decorators/MethodMapping.js +51 -53
- package/dist/cjs/decorators/MethodMapping.js.map +2 -2
- package/dist/cjs/decorators/index.js +3 -248
- package/dist/cjs/decorators/index.js.map +4 -4
- package/dist/cjs/endpoints/CrossDomainHeaderEndPoint.js +7 -8
- package/dist/cjs/endpoints/CrossDomainHeaderEndPoint.js.map +1 -1
- package/dist/cjs/endpoints/EndPoint.js +0 -2
- package/dist/cjs/endpoints/EndPoint.js.map +1 -1
- package/dist/cjs/endpoints/HeaderEndPoint.js +2 -4
- package/dist/cjs/endpoints/HeaderEndPoint.js.map +1 -1
- package/dist/cjs/endpoints/index.js +7 -54
- package/dist/cjs/endpoints/index.js.map +3 -3
- package/dist/cjs/errors/BadRequestError.js +5 -16
- package/dist/cjs/errors/BadRequestError.js.map +3 -3
- package/dist/cjs/errors/ForbiddenError.js +5 -16
- package/dist/cjs/errors/ForbiddenError.js.map +3 -3
- package/dist/cjs/errors/HttpError.js +7 -5
- package/dist/cjs/errors/HttpError.js.map +1 -1
- package/dist/cjs/errors/InternalServerError.js +5 -16
- package/dist/cjs/errors/InternalServerError.js.map +3 -3
- package/dist/cjs/errors/NotFoundError.js +5 -16
- package/dist/cjs/errors/NotFoundError.js.map +3 -3
- package/dist/cjs/errors/UnauthorizedError.js +5 -16
- package/dist/cjs/errors/UnauthorizedError.js.map +3 -3
- package/dist/cjs/errors/index.js +13 -64
- package/dist/cjs/errors/index.js.map +3 -3
- package/dist/cjs/filters/CacheFilter.js +14 -17
- package/dist/cjs/filters/CacheFilter.js.map +2 -2
- package/dist/cjs/filters/Filter.js +0 -2
- package/dist/cjs/filters/Filter.js.map +1 -1
- package/dist/cjs/filters/HttpStatusFilter.js +2 -4
- package/dist/cjs/filters/HttpStatusFilter.js.map +1 -1
- package/dist/cjs/filters/OpenApi3Filter.js +8 -20
- package/dist/cjs/filters/OpenApi3Filter.js.map +3 -3
- package/dist/cjs/filters/ResourceFilter.js +7 -7
- package/dist/cjs/filters/ResourceFilter.js.map +1 -1
- package/dist/cjs/filters/ThrowFilter.js +2 -4
- package/dist/cjs/filters/ThrowFilter.js.map +1 -1
- package/dist/cjs/filters/index.js +13 -299
- package/dist/cjs/filters/index.js.map +4 -4
- package/dist/cjs/index.d.ts +2 -12
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +2 -1734
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/inject/InjectSituationType.js +0 -2
- package/dist/cjs/inject/InjectSituationType.js.map +1 -1
- package/dist/cjs/inject/index.js +3 -16
- package/dist/cjs/inject/index.js.map +4 -4
- package/dist/cjs/lifecycle/OnInit.js +0 -2
- package/dist/cjs/lifecycle/OnInit.js.map +1 -1
- package/dist/cjs/lifecycle/index.js +6 -2
- package/dist/cjs/lifecycle/index.js.map +1 -1
- package/dist/cjs/models/RequestResponse.js +26 -33
- package/dist/cjs/models/RequestResponse.js.map +3 -3
- package/dist/cjs/models/datas/HeaderData.js +2 -4
- package/dist/cjs/models/datas/HeaderData.js.map +1 -1
- package/dist/cjs/models/datas/MultipartData.js +0 -2
- package/dist/cjs/models/datas/MultipartData.js.map +1 -1
- package/dist/cjs/models/datas/ReqHeader.js +65 -4
- package/dist/cjs/models/datas/ReqHeader.js.map +1 -1
- package/dist/cjs/models/datas/Resource.js +8 -480
- package/dist/cjs/models/datas/Resource.js.map +4 -4
- package/dist/cjs/models/datas/body/ReqFormUrlBody.js +2 -4
- package/dist/cjs/models/datas/body/ReqFormUrlBody.js.map +1 -1
- package/dist/cjs/models/datas/body/ReqJsonBody.js +2 -4
- package/dist/cjs/models/datas/body/ReqJsonBody.js.map +1 -1
- package/dist/cjs/models/datas/body/ReqMultipartFormBody.js +2 -4
- package/dist/cjs/models/datas/body/ReqMultipartFormBody.js.map +1 -1
- package/dist/cjs/models/index.js +19 -574
- package/dist/cjs/models/index.js.map +4 -4
- package/dist/cjs/models/method/patch/PatchJson.js +2 -4
- package/dist/cjs/models/method/patch/PatchJson.js.map +1 -1
- package/dist/cjs/option/HttpServerOption.js +16 -11
- package/dist/cjs/option/HttpServerOption.js.map +1 -1
- package/dist/cjs/option/index.js +3 -50
- package/dist/cjs/option/index.js.map +3 -3
- package/dist/cjs/resolvers/Resolver.js +0 -2
- package/dist/cjs/resolvers/Resolver.js.map +1 -1
- package/dist/cjs/resolvers/ResourceResolver.js +10 -538
- package/dist/cjs/resolvers/ResourceResolver.js.map +4 -4
- package/dist/cjs/resolvers/index.js +5 -552
- package/dist/cjs/resolvers/index.js.map +4 -4
- package/dist/cjs/session/SessionManager.js +6 -479
- package/dist/cjs/session/SessionManager.js.map +4 -4
- package/dist/cjs/session/index.js +3 -560
- package/dist/cjs/session/index.js.map +4 -4
- package/dist/esm/SimpleBootHttpServer.d.ts +2 -1
- package/dist/esm/SimpleBootHttpServer.d.ts.map +1 -1
- package/dist/esm/SimpleBootHttpServer.js +37 -656
- package/dist/esm/SimpleBootHttpServer.js.map +4 -4
- package/dist/esm/codes/HttpHeaders.js +0 -1
- package/dist/esm/codes/HttpHeaders.js.map +1 -1
- package/dist/esm/codes/HttpMethod.js +0 -1
- package/dist/esm/codes/HttpMethod.js.map +1 -1
- package/dist/esm/codes/HttpStatus.js +0 -1
- package/dist/esm/codes/HttpStatus.js.map +1 -1
- package/dist/esm/codes/Mimes.js +0 -1
- package/dist/esm/codes/Mimes.js.map +1 -1
- package/dist/esm/codes/index.js +4 -115
- package/dist/esm/codes/index.js.map +4 -4
- package/dist/esm/decorators/MethodMapping.d.ts +0 -1
- package/dist/esm/decorators/MethodMapping.d.ts.map +1 -1
- package/dist/esm/decorators/MethodMapping.js +51 -52
- package/dist/esm/decorators/MethodMapping.js.map +2 -2
- package/dist/esm/decorators/index.js +1 -210
- package/dist/esm/decorators/index.js.map +4 -4
- package/dist/esm/endpoints/CrossDomainHeaderEndPoint.js +7 -7
- package/dist/esm/endpoints/CrossDomainHeaderEndPoint.js.map +1 -1
- package/dist/esm/endpoints/HeaderEndPoint.js +2 -3
- package/dist/esm/endpoints/HeaderEndPoint.js.map +1 -1
- package/dist/esm/endpoints/index.js +3 -45
- package/dist/esm/endpoints/index.js.map +3 -3
- package/dist/esm/errors/BadRequestError.js +5 -13
- package/dist/esm/errors/BadRequestError.js.map +3 -3
- package/dist/esm/errors/ForbiddenError.js +5 -13
- package/dist/esm/errors/ForbiddenError.js.map +3 -3
- package/dist/esm/errors/HttpError.js +7 -4
- package/dist/esm/errors/HttpError.js.map +1 -1
- package/dist/esm/errors/InternalServerError.js +5 -13
- package/dist/esm/errors/InternalServerError.js.map +3 -3
- package/dist/esm/errors/NotFoundError.js +5 -13
- package/dist/esm/errors/NotFoundError.js.map +3 -3
- package/dist/esm/errors/UnauthorizedError.js +5 -13
- package/dist/esm/errors/UnauthorizedError.js.map +3 -3
- package/dist/esm/errors/index.js +6 -51
- package/dist/esm/errors/index.js.map +3 -3
- package/dist/esm/filters/CacheFilter.js +14 -16
- package/dist/esm/filters/CacheFilter.js.map +2 -2
- package/dist/esm/filters/HttpStatusFilter.js +2 -3
- package/dist/esm/filters/HttpStatusFilter.js.map +1 -1
- package/dist/esm/filters/OpenApi3Filter.js +7 -16
- package/dist/esm/filters/OpenApi3Filter.js.map +3 -3
- package/dist/esm/filters/ResourceFilter.js +7 -6
- package/dist/esm/filters/ResourceFilter.js.map +1 -1
- package/dist/esm/filters/ThrowFilter.js +2 -3
- package/dist/esm/filters/ThrowFilter.js.map +1 -1
- package/dist/esm/filters/index.js +6 -277
- package/dist/esm/filters/index.js.map +4 -4
- package/dist/esm/index.d.ts +2 -12
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -1659
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/inject/InjectSituationType.js +0 -1
- package/dist/esm/inject/InjectSituationType.js.map +1 -1
- package/dist/esm/inject/index.js +1 -8
- package/dist/esm/inject/index.js.map +4 -4
- package/dist/esm/lifecycle/index.js +1 -0
- package/dist/esm/lifecycle/index.js.map +3 -3
- package/dist/esm/models/RequestResponse.js +23 -29
- package/dist/esm/models/RequestResponse.js.map +3 -3
- package/dist/esm/models/datas/HeaderData.js +2 -3
- package/dist/esm/models/datas/HeaderData.js.map +1 -1
- package/dist/esm/models/datas/ReqHeader.js +65 -3
- package/dist/esm/models/datas/ReqHeader.js.map +1 -1
- package/dist/esm/models/datas/Resource.js +7 -478
- package/dist/esm/models/datas/Resource.js.map +4 -4
- package/dist/esm/models/datas/body/ReqFormUrlBody.js +2 -3
- package/dist/esm/models/datas/body/ReqFormUrlBody.js.map +1 -1
- package/dist/esm/models/datas/body/ReqJsonBody.js +2 -3
- package/dist/esm/models/datas/body/ReqJsonBody.js.map +1 -1
- package/dist/esm/models/datas/body/ReqMultipartFormBody.js +2 -3
- package/dist/esm/models/datas/body/ReqMultipartFormBody.js.map +1 -1
- package/dist/esm/models/index.js +9 -548
- package/dist/esm/models/index.js.map +4 -4
- package/dist/esm/models/method/patch/PatchJson.js +2 -3
- package/dist/esm/models/method/patch/PatchJson.js.map +1 -1
- package/dist/esm/option/HttpServerOption.js +16 -10
- package/dist/esm/option/HttpServerOption.js.map +1 -1
- package/dist/esm/option/index.js +1 -42
- package/dist/esm/option/index.js.map +3 -3
- package/dist/esm/resolvers/ResourceResolver.js +8 -526
- package/dist/esm/resolvers/ResourceResolver.js.map +4 -4
- package/dist/esm/resolvers/index.js +2 -537
- package/dist/esm/resolvers/index.js.map +4 -4
- package/dist/esm/session/SessionManager.js +5 -477
- package/dist/esm/session/SessionManager.js.map +3 -3
- package/dist/esm/session/index.js +1 -552
- package/dist/esm/session/index.js.map +3 -3
- package/dist/esm-bundle/dooboostore-simple-boot-http-server.esm.js +3 -1659
- package/dist/esm-bundle/dooboostore-simple-boot-http-server.esm.js.map +4 -4
- package/dist/umd-bundle/dooboostore-simple-boot-http-server.umd.js +2 -1673
- package/dist/umd-bundle/dooboostore-simple-boot-http-server.umd.js.map +4 -4
- package/package.json +15 -12
|
@@ -15,664 +15,44 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// src/SimpleBootHttpServer.ts
|
|
20
18
|
var SimpleBootHttpServer_exports = {};
|
|
21
19
|
__export(SimpleBootHttpServer_exports, {
|
|
22
20
|
SimpleBootHttpServer: () => SimpleBootHttpServer
|
|
23
21
|
});
|
|
24
22
|
module.exports = __toCommonJS(SimpleBootHttpServer_exports);
|
|
25
23
|
var import_SimpleApplication = require("@dooboostore/simple-boot/SimpleApplication");
|
|
26
|
-
|
|
27
|
-
// src/option/HttpServerOption.ts
|
|
28
|
-
var import_SimOption = require("@dooboostore/simple-boot/SimOption");
|
|
29
|
-
var HttpServerOption = class _HttpServerOption extends import_SimOption.SimOption {
|
|
30
|
-
static {
|
|
31
|
-
this.DEFAULT_PORT = 8081;
|
|
32
|
-
}
|
|
33
|
-
static {
|
|
34
|
-
this.DEFAULT_HOSTNAME = "127.0.0.1";
|
|
35
|
-
}
|
|
36
|
-
constructor({ serverOption, listen, filters, requestEndPoints, closeEndPoints, errorEndPoints, sessionOption, globalAdvice, fileUploadTempPath, noSuchRouteEndPointMappingThrow, transactionManagerFactory } = {}, initSimOption) {
|
|
37
|
-
super(initSimOption);
|
|
38
|
-
this.serverOption = serverOption;
|
|
39
|
-
this.listen = Object.assign({ port: _HttpServerOption.DEFAULT_PORT, hostname: _HttpServerOption.DEFAULT_HOSTNAME }, listen);
|
|
40
|
-
this.filters = filters;
|
|
41
|
-
this.requestEndPoints = requestEndPoints;
|
|
42
|
-
this.closeEndPoints = closeEndPoints;
|
|
43
|
-
this.errorEndPoints = errorEndPoints;
|
|
44
|
-
this.sessionOption = Object.assign({ key: "SBSESSIONID", expiredTime: 1e3 * 60 * 30 }, sessionOption);
|
|
45
|
-
this.globalAdvice = globalAdvice;
|
|
46
|
-
this.fileUploadTempPath = fileUploadTempPath;
|
|
47
|
-
this.noSuchRouteEndPointMappingThrow = noSuchRouteEndPointMappingThrow;
|
|
48
|
-
this.transactionManagerFactory = transactionManagerFactory;
|
|
49
|
-
}
|
|
50
|
-
get hostname() {
|
|
51
|
-
return this.listen.hostname;
|
|
52
|
-
}
|
|
53
|
-
get port() {
|
|
54
|
-
return this.listen.port;
|
|
55
|
-
}
|
|
56
|
-
get protocol() {
|
|
57
|
-
return this.isSecure ? "https" : "http";
|
|
58
|
-
}
|
|
59
|
-
get address() {
|
|
60
|
-
return `${this.protocol}://${this.hostname}:${this.port}`;
|
|
61
|
-
}
|
|
62
|
-
get isSecure() {
|
|
63
|
-
return this.serverOption && "key" in this.serverOption && "cert" in this.serverOption;
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// src/SimpleBootHttpServer.ts
|
|
24
|
+
var import_HttpServerOption = require("./option/HttpServerOption");
|
|
68
25
|
var import_http = require("http");
|
|
69
26
|
var import_https = require("https");
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
var
|
|
73
|
-
var
|
|
74
|
-
var
|
|
75
|
-
|
|
76
|
-
// src/models/datas/body/ReqFormUrlBody.ts
|
|
77
|
-
var ReqFormUrlBody = class {
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
// src/models/datas/body/ReqJsonBody.ts
|
|
81
|
-
var ReqJsonBody = class {
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
// src/models/datas/ReqHeader.ts
|
|
85
|
-
var ReqHeader = class {
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
// src/models/RequestResponse.ts
|
|
89
|
-
var import_node_gzip = require("node-gzip");
|
|
90
|
-
var import_FileUtils = require("@dooboostore/core-node/file/FileUtils");
|
|
91
|
-
var import_ConvertUtils = require("@dooboostore/core/convert/ConvertUtils");
|
|
92
|
-
var import_ConvertUtils2 = require("@dooboostore/core-node/convert/ConvertUtils");
|
|
93
|
-
var RequestResponse = class _RequestResponse {
|
|
94
|
-
// protected sessionManager?: SessionManager;
|
|
95
|
-
// constructor(req: IncomingMessage, res: ServerResponse);
|
|
96
|
-
// constructor(req: RequestResponse);
|
|
97
|
-
// constructor(req: IncomingMessage, res: ServerResponse, sessionManager?: SessionManager);
|
|
98
|
-
// constructor(req: IncomingMessage | RequestResponse, res?: ServerResponse, sessionManager?: SessionManager) {
|
|
99
|
-
// // this.req = req;
|
|
100
|
-
// // this.res = res;
|
|
101
|
-
// if (req instanceof RequestResponse) {
|
|
102
|
-
// this.req = req.req;
|
|
103
|
-
// this.res = req.res;
|
|
104
|
-
// this.sessionManager = req.sessionManager;
|
|
105
|
-
// } else {
|
|
106
|
-
// this.req = req;
|
|
107
|
-
// this.res = res!;
|
|
108
|
-
// this.sessionManager = sessionManager;
|
|
109
|
-
// }
|
|
110
|
-
// }
|
|
111
|
-
constructor(req, res, config) {
|
|
112
|
-
if (req instanceof _RequestResponse) {
|
|
113
|
-
this.req = req.req;
|
|
114
|
-
this.res = req.res;
|
|
115
|
-
this.config = config;
|
|
116
|
-
} else {
|
|
117
|
-
this.req = req;
|
|
118
|
-
this.res = res;
|
|
119
|
-
this.config = config;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
get reqSocket() {
|
|
123
|
-
return this.req.socket;
|
|
124
|
-
}
|
|
125
|
-
get reqCookieMap() {
|
|
126
|
-
let cookies = this.reqHeader("Cookie" /* Cookie */) ?? "";
|
|
127
|
-
if (Array.isArray(cookies)) {
|
|
128
|
-
cookies = cookies.join(";");
|
|
129
|
-
}
|
|
130
|
-
const map = /* @__PURE__ */ new Map();
|
|
131
|
-
cookies.split(";").map((it) => it.trim().split("=")).forEach((it) => {
|
|
132
|
-
map.set(it[0], it[1]);
|
|
133
|
-
});
|
|
134
|
-
return map;
|
|
135
|
-
}
|
|
136
|
-
reqCookieGet(key) {
|
|
137
|
-
return this.reqCookieMap.get(key);
|
|
138
|
-
}
|
|
139
|
-
get reqRemoteAddress() {
|
|
140
|
-
const ipHeader = this.req.headers["x-forwarded-for"];
|
|
141
|
-
let ip = this.req.socket.remoteAddress;
|
|
142
|
-
if (Array.isArray(ipHeader)) {
|
|
143
|
-
ip = ipHeader.join(",").split(",").shift();
|
|
144
|
-
} else if (typeof ipHeader === "string") {
|
|
145
|
-
ip = ipHeader.split(",").shift();
|
|
146
|
-
}
|
|
147
|
-
return ip;
|
|
148
|
-
}
|
|
149
|
-
get reqUrlObject() {
|
|
150
|
-
return new import_url.URL(this.reqUrl, `${this.reqSocket ? "https://" : "http"}${this.reqHost ?? "localhost"}`);
|
|
151
|
-
}
|
|
152
|
-
get reqUrlPathName() {
|
|
153
|
-
return this.reqUrlObj().pathname ?? "";
|
|
154
|
-
}
|
|
155
|
-
get reqUrl() {
|
|
156
|
-
return this.req.url ?? "";
|
|
157
|
-
}
|
|
158
|
-
reqUrlObj(config) {
|
|
159
|
-
return new import_url.URL(`${config?.scheme ?? "http"}://${config?.host ? config?.host : this.reqHeaderFirst("Host" /* Host */) ?? "localhost"}${this.req.url ?? ""}`);
|
|
160
|
-
}
|
|
161
|
-
get reqUrlSearchParamTuples() {
|
|
162
|
-
return Array.from(this.reqUrlObj().searchParams);
|
|
163
|
-
}
|
|
164
|
-
get reqUrlSearchParams() {
|
|
165
|
-
return this.reqUrlObj().searchParams;
|
|
166
|
-
}
|
|
167
|
-
get reqUrlSearchParamsObj() {
|
|
168
|
-
const entries = this.reqUrlObj().searchParams;
|
|
169
|
-
return import_ConvertUtils.ConvertUtils.toObject(entries);
|
|
170
|
-
}
|
|
171
|
-
get reqPathSearchParamUrl() {
|
|
172
|
-
const reqUrlObj = this.reqUrlObj();
|
|
173
|
-
return reqUrlObj.pathname + (reqUrlObj.searchParams.toString() ? "?" + reqUrlObj.searchParams.toString() : "");
|
|
174
|
-
}
|
|
175
|
-
get reqReadable() {
|
|
176
|
-
return this.req.readable;
|
|
177
|
-
}
|
|
178
|
-
get reqIntent() {
|
|
179
|
-
return new import_Intent.Intent(this.reqPathSearchParamUrl);
|
|
180
|
-
}
|
|
181
|
-
reqHasContentTypeHeader(mime) {
|
|
182
|
-
return (this.reqHeaderFirst("Content-Type" /* ContentType */) ?? "").toLowerCase().indexOf(mime.toLocaleLowerCase()) > -1;
|
|
183
|
-
}
|
|
184
|
-
reqHasAcceptHeader(mime) {
|
|
185
|
-
return (this.reqHeaderFirst("Accept" /* Accept */) ?? "").toLowerCase().indexOf(mime.toLocaleLowerCase()) > -1;
|
|
186
|
-
}
|
|
187
|
-
reqBodyData() {
|
|
188
|
-
return new Promise((resolve, reject) => {
|
|
189
|
-
if (this.reqReadable) {
|
|
190
|
-
const data = [];
|
|
191
|
-
this.req.on("data", (chunk) => data.push(chunk));
|
|
192
|
-
this.req.on("error", (err) => reject(err));
|
|
193
|
-
this.req.on("end", () => {
|
|
194
|
-
this.reqBodyChunk = import_buffer.Buffer.concat(data);
|
|
195
|
-
resolve(this.reqBodyChunk);
|
|
196
|
-
});
|
|
197
|
-
} else {
|
|
198
|
-
resolve(this.reqBodyChunk ?? import_buffer.Buffer.alloc(0));
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
resBodyData() {
|
|
203
|
-
return this.resWriteChunk;
|
|
204
|
-
}
|
|
205
|
-
async reqBodyMultipartFormDataObject() {
|
|
206
|
-
const m = await this.reqBodyMultipartFormData();
|
|
207
|
-
const formData = {};
|
|
208
|
-
for (const it of m) {
|
|
209
|
-
if (it.isFile) {
|
|
210
|
-
formData[it.name] = await import_FileUtils.FileUtils.writeFile(it.value, { originalName: it.filename });
|
|
211
|
-
} else {
|
|
212
|
-
const target = formData[it.name];
|
|
213
|
-
if (Array.isArray(target)) {
|
|
214
|
-
target.push(it.value);
|
|
215
|
-
} else if (typeof target === "string") {
|
|
216
|
-
formData[it.name] = [target, it.value];
|
|
217
|
-
} else {
|
|
218
|
-
formData[it.name] = it.value;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
;
|
|
223
|
-
return formData;
|
|
224
|
-
}
|
|
225
|
-
reqBodyMultipartFormData() {
|
|
226
|
-
return new Promise((resolve, reject) => {
|
|
227
|
-
const contentTypeHeader = this.req.headers["content-type"];
|
|
228
|
-
if (!contentTypeHeader || !contentTypeHeader.startsWith("multipart/form-data")) {
|
|
229
|
-
return reject(new Error("Invalid Content-Type. Expected multipart/form-data."));
|
|
230
|
-
}
|
|
231
|
-
const boundaryMatch = contentTypeHeader.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
|
|
232
|
-
if (!boundaryMatch) {
|
|
233
|
-
return reject(new Error("Boundary not found in Content-Type header."));
|
|
234
|
-
}
|
|
235
|
-
const boundary = boundaryMatch[1] || boundaryMatch[2];
|
|
236
|
-
if (!boundary) {
|
|
237
|
-
return reject(new Error("Failed to extract boundary."));
|
|
238
|
-
}
|
|
239
|
-
const boundaryBuffer = import_buffer.Buffer.from(`--${boundary}`);
|
|
240
|
-
const crlfBuffer = import_buffer.Buffer.from("\r\n");
|
|
241
|
-
const doubleCrlfBuffer = import_buffer.Buffer.from("\r\n\r\n");
|
|
242
|
-
const chunks = [];
|
|
243
|
-
let totalLength = 0;
|
|
244
|
-
this.req.on("data", (chunk) => {
|
|
245
|
-
chunks.push(chunk);
|
|
246
|
-
totalLength += chunk.length;
|
|
247
|
-
});
|
|
248
|
-
this.req.on("error", (err) => {
|
|
249
|
-
reject(err);
|
|
250
|
-
});
|
|
251
|
-
this.req.on("end", () => {
|
|
252
|
-
if (totalLength === 0) {
|
|
253
|
-
return resolve([]);
|
|
254
|
-
}
|
|
255
|
-
const fullBuffer = import_buffer.Buffer.concat(chunks, totalLength);
|
|
256
|
-
const parsedParts = [];
|
|
257
|
-
let currentPosition = 0;
|
|
258
|
-
let boundaryStartIndex = fullBuffer.indexOf(boundaryBuffer, currentPosition);
|
|
259
|
-
if (boundaryStartIndex === -1) {
|
|
260
|
-
return reject(new Error("Initial boundary not found."));
|
|
261
|
-
}
|
|
262
|
-
currentPosition = boundaryStartIndex + boundaryBuffer.length;
|
|
263
|
-
if (fullBuffer.slice(currentPosition, currentPosition + crlfBuffer.length).equals(crlfBuffer)) {
|
|
264
|
-
currentPosition += crlfBuffer.length;
|
|
265
|
-
}
|
|
266
|
-
while (currentPosition < fullBuffer.length) {
|
|
267
|
-
const nextBoundaryIndex = fullBuffer.indexOf(boundaryBuffer, currentPosition);
|
|
268
|
-
if (nextBoundaryIndex === -1) {
|
|
269
|
-
break;
|
|
270
|
-
}
|
|
271
|
-
let partEndIndex = nextBoundaryIndex;
|
|
272
|
-
if (partEndIndex > crlfBuffer.length && fullBuffer.slice(partEndIndex - crlfBuffer.length, partEndIndex).equals(crlfBuffer)) {
|
|
273
|
-
partEndIndex -= crlfBuffer.length;
|
|
274
|
-
}
|
|
275
|
-
const partBuffer = fullBuffer.slice(currentPosition, partEndIndex);
|
|
276
|
-
const headerBodySeparatorIndex = partBuffer.indexOf(doubleCrlfBuffer);
|
|
277
|
-
if (headerBodySeparatorIndex === -1) {
|
|
278
|
-
console.warn("Skipping malformed part: no header/body separator found.");
|
|
279
|
-
currentPosition = nextBoundaryIndex + boundaryBuffer.length;
|
|
280
|
-
if (fullBuffer.slice(currentPosition, currentPosition + crlfBuffer.length).equals(crlfBuffer)) {
|
|
281
|
-
currentPosition += crlfBuffer.length;
|
|
282
|
-
}
|
|
283
|
-
if (fullBuffer.slice(currentPosition, currentPosition + 2).toString() === "--") break;
|
|
284
|
-
continue;
|
|
285
|
-
}
|
|
286
|
-
const headerBuffer = partBuffer.slice(0, headerBodySeparatorIndex);
|
|
287
|
-
const bodyBuffer = partBuffer.slice(headerBodySeparatorIndex + doubleCrlfBuffer.length);
|
|
288
|
-
const headersStr = headerBuffer.toString("utf-8");
|
|
289
|
-
const headers = {};
|
|
290
|
-
headersStr.split("\r\n").forEach((line) => {
|
|
291
|
-
const colonIndex = line.indexOf(":");
|
|
292
|
-
if (colonIndex > 0) {
|
|
293
|
-
const key = line.substring(0, colonIndex).trim().toLowerCase();
|
|
294
|
-
const value = line.substring(colonIndex + 1).trim();
|
|
295
|
-
headers[key] = value;
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
const contentDisposition = headers["content-disposition"];
|
|
299
|
-
if (!contentDisposition) {
|
|
300
|
-
console.warn("Skipping part: no Content-Disposition header.");
|
|
301
|
-
currentPosition = nextBoundaryIndex + boundaryBuffer.length;
|
|
302
|
-
if (fullBuffer.slice(currentPosition, currentPosition + crlfBuffer.length).equals(crlfBuffer)) {
|
|
303
|
-
currentPosition += crlfBuffer.length;
|
|
304
|
-
}
|
|
305
|
-
if (fullBuffer.slice(currentPosition, currentPosition + 2).toString() === "--") break;
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
|
-
const nameMatch = contentDisposition.match(/name="([^"]+)"/i);
|
|
309
|
-
const filenameMatch = contentDisposition.match(/filename="([^"]+)"/i);
|
|
310
|
-
const name = nameMatch ? nameMatch[1] : null;
|
|
311
|
-
const filename = filenameMatch ? filenameMatch[1] : null;
|
|
312
|
-
const contentType = headers["content-type"] || null;
|
|
313
|
-
if (name) {
|
|
314
|
-
const isFile = !!filename;
|
|
315
|
-
const multipartData = {
|
|
316
|
-
name,
|
|
317
|
-
isFile,
|
|
318
|
-
// filename이 있으면 파일로 간주
|
|
319
|
-
filename,
|
|
320
|
-
contentType,
|
|
321
|
-
value: isFile ? bodyBuffer : bodyBuffer.toString("utf-8")
|
|
322
|
-
};
|
|
323
|
-
parsedParts.push(multipartData);
|
|
324
|
-
} else {
|
|
325
|
-
console.warn("Skipping part: 'name' not found in Content-Disposition.");
|
|
326
|
-
}
|
|
327
|
-
currentPosition = nextBoundaryIndex + boundaryBuffer.length;
|
|
328
|
-
if (fullBuffer.slice(currentPosition, currentPosition + crlfBuffer.length).equals(crlfBuffer)) {
|
|
329
|
-
currentPosition += crlfBuffer.length;
|
|
330
|
-
}
|
|
331
|
-
if (fullBuffer.slice(currentPosition, currentPosition + 2).toString() === "--") {
|
|
332
|
-
break;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
resolve(parsedParts);
|
|
336
|
-
});
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
async reqBodyStringData() {
|
|
340
|
-
const data = (await this.reqBodyData()).toString();
|
|
341
|
-
return data;
|
|
342
|
-
}
|
|
343
|
-
async reqBodyJsonData() {
|
|
344
|
-
return JSON.parse(await this.reqBodyStringData());
|
|
345
|
-
}
|
|
346
|
-
async reqBodyFormUrlData() {
|
|
347
|
-
const data = await this.reqBodyStringData();
|
|
348
|
-
const formData = {};
|
|
349
|
-
Array.from(new import_url.URLSearchParams(data).entries()).forEach(([k, v]) => {
|
|
350
|
-
const target = formData[k];
|
|
351
|
-
if (Array.isArray(target)) {
|
|
352
|
-
target.push(v);
|
|
353
|
-
} else if (typeof target === "string") {
|
|
354
|
-
formData[k] = [target, v];
|
|
355
|
-
} else {
|
|
356
|
-
formData[k] = v;
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
return formData;
|
|
360
|
-
}
|
|
361
|
-
async reqBodyReqFormUrlBody() {
|
|
362
|
-
const data = await this.reqBodyFormUrlData();
|
|
363
|
-
return Object.assign(new ReqFormUrlBody(), data);
|
|
364
|
-
}
|
|
365
|
-
async reqBodyReqJsonBody() {
|
|
366
|
-
const data = await this.reqBodyStringData();
|
|
367
|
-
return Object.assign(new ReqJsonBody(), data ? JSON.parse(data) : {});
|
|
368
|
-
}
|
|
369
|
-
// reqBodyReqMultipartFormBody(): Promise<ReqMultipartFormBody> {
|
|
370
|
-
// return this.reqBodyMultipartFormData().then(it => new ReqMultipartFormBody(it))
|
|
371
|
-
// }
|
|
372
|
-
resBodyJsonData() {
|
|
373
|
-
const data = import_ConvertUtils2.ConvertUtils.toString(this.resBodyData());
|
|
374
|
-
return data ? JSON.parse(data) : null;
|
|
375
|
-
}
|
|
376
|
-
resBodyStringData() {
|
|
377
|
-
return import_ConvertUtils2.ConvertUtils.toString(this.resBodyData());
|
|
378
|
-
}
|
|
379
|
-
reqMethod() {
|
|
380
|
-
return this.req.method?.toUpperCase();
|
|
381
|
-
}
|
|
382
|
-
reqHeader(key) {
|
|
383
|
-
return this.req.headers[key.toLowerCase()];
|
|
384
|
-
}
|
|
385
|
-
get reqHost() {
|
|
386
|
-
return this.reqHeaderFirst("Host" /* Host */);
|
|
387
|
-
}
|
|
388
|
-
get reqHeaderObj() {
|
|
389
|
-
const h = new ReqHeader();
|
|
390
|
-
Object.entries(this.req.headers).forEach(([k, v]) => {
|
|
391
|
-
h[k] = v;
|
|
392
|
-
});
|
|
393
|
-
return h;
|
|
394
|
-
}
|
|
395
|
-
reqHeaderFirst(key, defaultValue) {
|
|
396
|
-
const header = this.req.headers[key.toLowerCase()];
|
|
397
|
-
if (header && Array.isArray(header)) {
|
|
398
|
-
return header[0] ?? defaultValue;
|
|
399
|
-
} else {
|
|
400
|
-
return header ?? defaultValue;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
reqAuthorizationHeader() {
|
|
404
|
-
return this.reqHeaderFirst("Authorization" /* Authorization */);
|
|
405
|
-
}
|
|
406
|
-
reqRefreshTokenHeader() {
|
|
407
|
-
return this.reqHeaderFirst("Authorization" /* Authorization */);
|
|
408
|
-
}
|
|
409
|
-
// eslint-disable-next-line no-dupe-class-members
|
|
410
|
-
resStatusCode(code) {
|
|
411
|
-
if (code) {
|
|
412
|
-
this.res.statusCode = code;
|
|
413
|
-
return new RequestResponseChain(this.req, this.res, this.config, this.res.statusCode);
|
|
414
|
-
} else {
|
|
415
|
-
return this.res.statusCode;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
resHeader(key) {
|
|
419
|
-
return this.res.getHeader(key.toLowerCase());
|
|
420
|
-
}
|
|
421
|
-
resHeaderFirst(key, defaultValue) {
|
|
422
|
-
const header = this.res.getHeader(key.toLowerCase());
|
|
423
|
-
if (header && Array.isArray(header)) {
|
|
424
|
-
return header[0] ?? defaultValue;
|
|
425
|
-
} else {
|
|
426
|
-
return header ?? defaultValue;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
async reqSession() {
|
|
430
|
-
if (this.config.sessionManager) {
|
|
431
|
-
return (await this.config.sessionManager.session(this)).dataSet.data;
|
|
432
|
-
} else {
|
|
433
|
-
return Promise.reject(new Error("Not SessionManager"));
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
reqSessionSet(key, value) {
|
|
437
|
-
this.reqSession[key] = value;
|
|
438
|
-
}
|
|
439
|
-
reqSessionGet(key) {
|
|
440
|
-
const session = this.reqSession;
|
|
441
|
-
if (session) {
|
|
442
|
-
return session[key];
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
resSetStatusCode(statusCode) {
|
|
446
|
-
this.res.statusCode = statusCode;
|
|
447
|
-
return this.createRequestResponseChain(this.res.statusCode);
|
|
448
|
-
}
|
|
449
|
-
// resEnd() {
|
|
450
|
-
// this.res.end();
|
|
451
|
-
// }
|
|
452
|
-
// eslint-disable-next-line no-undef
|
|
453
|
-
resWrite(chunk, encoding = "utf8") {
|
|
454
|
-
this.resWriteChunk = chunk;
|
|
455
|
-
return this.createRequestResponseChain(this.resWriteChunk);
|
|
456
|
-
}
|
|
457
|
-
// eslint-disable-next-line no-undef
|
|
458
|
-
resWriteJson(chunk, encoding = "utf8") {
|
|
459
|
-
return this.resWrite(JSON.stringify(chunk), encoding);
|
|
460
|
-
}
|
|
461
|
-
resSetHeader(key, value) {
|
|
462
|
-
return this.createRequestResponseChain(this.res.setHeader(key.toLowerCase(), value));
|
|
463
|
-
}
|
|
464
|
-
resAddHeader(key, value) {
|
|
465
|
-
const existingValue = this.res.getHeader(key.toLowerCase());
|
|
466
|
-
const newValue = Array.isArray(existingValue) ? existingValue.concat(value) : existingValue ? [existingValue.toString(), ...[].concat(value)] : value;
|
|
467
|
-
return this.createRequestResponseChain(this.res.setHeader(key.toLowerCase(), newValue));
|
|
468
|
-
}
|
|
469
|
-
resSetHeaders(headers) {
|
|
470
|
-
Object.entries(headers).forEach(([key, value]) => this.resSetHeader(key, value));
|
|
471
|
-
return this.createRequestResponseChain();
|
|
472
|
-
}
|
|
473
|
-
resAddHeaders(headers) {
|
|
474
|
-
Object.entries(headers).forEach(([key, value]) => this.resAddHeader(key, value));
|
|
475
|
-
return this.createRequestResponseChain();
|
|
476
|
-
}
|
|
477
|
-
// 마지막 종료될때 타는거.
|
|
478
|
-
async resEndChunk() {
|
|
479
|
-
const encoding = this.reqHeaderFirst("Accept-Encoding" /* AcceptEncoding */);
|
|
480
|
-
let data = this.resWriteChunk;
|
|
481
|
-
if (encoding?.includes("gzip")) {
|
|
482
|
-
data = await (0, import_node_gzip.gzip)(data);
|
|
483
|
-
this.resSetHeader("Content-Encoding" /* ContentEncoding */, "gzip");
|
|
484
|
-
}
|
|
485
|
-
this.res.end(data);
|
|
486
|
-
}
|
|
487
|
-
async resEnd(chunk) {
|
|
488
|
-
this.resWriteChunk = chunk ?? this.resWriteChunk;
|
|
489
|
-
if (this.req.readable) {
|
|
490
|
-
await this.reqBodyData();
|
|
491
|
-
await this.resEndChunk();
|
|
492
|
-
} else {
|
|
493
|
-
await this.resEndChunk();
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
// writeContinue(callback?: () => void) {
|
|
497
|
-
// this.res.writeContinue(callback);
|
|
498
|
-
// return new RequestResponseChain(this.req, this.res);
|
|
499
|
-
// }
|
|
500
|
-
// reqWrite(chunk?: any) {
|
|
501
|
-
// this.resWriteChunk = chunk;
|
|
502
|
-
// // this.res.write(chunk);
|
|
503
|
-
// return this.createRequestResponseChain();
|
|
504
|
-
// }
|
|
505
|
-
resWriteHead(statusCode, headers) {
|
|
506
|
-
return this.createRequestResponseChain(this.res.writeHead(statusCode, headers));
|
|
507
|
-
}
|
|
508
|
-
resWriteHeadEnd(statusCode, headers) {
|
|
509
|
-
this.createRequestResponseChain(this.res.writeHead(statusCode, headers));
|
|
510
|
-
this.res.end();
|
|
511
|
-
}
|
|
512
|
-
resIsDone() {
|
|
513
|
-
return this.res.finished || this.res.writableEnded || this.res.headersSent;
|
|
514
|
-
}
|
|
515
|
-
createRequestResponseChain(data) {
|
|
516
|
-
const requestResponseChain = new RequestResponseChain(this.req, this.res, this.config, data);
|
|
517
|
-
requestResponseChain.resWriteChunk = this.resWriteChunk;
|
|
518
|
-
requestResponseChain.reqBodyChunk = this.reqBodyChunk;
|
|
519
|
-
return requestResponseChain;
|
|
520
|
-
}
|
|
521
|
-
// res.on("readable", () => {
|
|
522
|
-
// console.log('readable???')
|
|
523
|
-
// });
|
|
524
|
-
// res.on('complete', function (details) {
|
|
525
|
-
// var size = details.req.bytes;
|
|
526
|
-
// console.log('complete-->', size)
|
|
527
|
-
// });
|
|
528
|
-
// res.on('finish', function() {
|
|
529
|
-
// console.log('finish??');
|
|
530
|
-
// });
|
|
531
|
-
// res.on('end', () => {
|
|
532
|
-
// console.log('end--?')
|
|
533
|
-
// });
|
|
534
|
-
};
|
|
535
|
-
var RequestResponseChain = class extends RequestResponse {
|
|
536
|
-
constructor(req, res, config, result) {
|
|
537
|
-
super(req, res, config);
|
|
538
|
-
this.result = result;
|
|
539
|
-
}
|
|
540
|
-
};
|
|
541
|
-
|
|
542
|
-
// src/decorators/MethodMapping.ts
|
|
543
|
-
var import_reflect_metadata = require("reflect-metadata");
|
|
544
|
-
var import_ReflectUtils = require("@dooboostore/core/reflect/ReflectUtils");
|
|
545
|
-
var MappingMetadataKey = Symbol("MappingMetadataKey");
|
|
546
|
-
var getUrlMapping = (target, propertyKey) => {
|
|
547
|
-
return import_ReflectUtils.ReflectUtils.getMetadata(MappingMetadataKey, target, propertyKey);
|
|
548
|
-
};
|
|
549
|
-
var getUrlMappings = (target) => {
|
|
550
|
-
if (target !== null && void 0 !== target && typeof target === "object") {
|
|
551
|
-
target = target.constructor;
|
|
552
|
-
}
|
|
553
|
-
return import_ReflectUtils.ReflectUtils.getMetadata(MappingMetadataKey, target);
|
|
554
|
-
};
|
|
555
|
-
|
|
556
|
-
// src/SimpleBootHttpServer.ts
|
|
27
|
+
var import_RequestResponse = require("./models/RequestResponse");
|
|
28
|
+
var import_MethodMapping = require("./decorators/MethodMapping");
|
|
29
|
+
var import_HttpStatus = require("./codes/HttpStatus");
|
|
30
|
+
var import_HttpHeaders = require("./codes/HttpHeaders");
|
|
31
|
+
var import_Mimes = require("./codes/Mimes");
|
|
557
32
|
var import_ExceptionDecorator = require("@dooboostore/simple-boot/decorators/exception/ExceptionDecorator");
|
|
558
33
|
var import_Inject = require("@dooboostore/simple-boot/decorators/inject/Inject");
|
|
559
|
-
var
|
|
34
|
+
var import_ReflectUtils = require("@dooboostore/core/reflect/ReflectUtils");
|
|
35
|
+
var import_ReqFormUrlBody = require("./models/datas/body/ReqFormUrlBody");
|
|
36
|
+
var import_ReqJsonBody = require("./models/datas/body/ReqJsonBody");
|
|
37
|
+
var import_ReqHeader = require("./models/datas/ReqHeader");
|
|
560
38
|
var import_RouterModule = require("@dooboostore/simple-boot/route/RouterModule");
|
|
561
|
-
|
|
562
|
-
// src/models/datas/body/ReqMultipartFormBody.ts
|
|
563
|
-
var ReqMultipartFormBody = class {
|
|
564
|
-
constructor(field = []) {
|
|
565
|
-
this.field = field;
|
|
566
|
-
}
|
|
567
|
-
};
|
|
568
|
-
|
|
569
|
-
// src/SimpleBootHttpServer.ts
|
|
39
|
+
var import_ReqMultipartFormBody = require("./models/datas/body/ReqMultipartFormBody");
|
|
570
40
|
var import_Validation = require("@dooboostore/simple-boot/decorators/validate/Validation");
|
|
571
41
|
var import_ValidException = require("@dooboostore/simple-boot/errors/ValidException");
|
|
572
|
-
|
|
573
|
-
// src/errors/HttpError.ts
|
|
574
|
-
var HttpError = class {
|
|
575
|
-
constructor({ status, message = "HttpError" }) {
|
|
576
|
-
this.name = "Error";
|
|
577
|
-
this.message = message;
|
|
578
|
-
this.status = status;
|
|
579
|
-
}
|
|
580
|
-
};
|
|
581
|
-
|
|
582
|
-
// src/SimpleBootHttpServer.ts
|
|
42
|
+
var import_HttpError = require("./errors/HttpError");
|
|
583
43
|
var import_Router = require("@dooboostore/simple-boot/decorators/route/Router");
|
|
584
|
-
var
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
var
|
|
588
|
-
|
|
589
|
-
constructor(option) {
|
|
590
|
-
this.option = option;
|
|
591
|
-
this.sessions = /* @__PURE__ */ new Map();
|
|
592
|
-
this.sessionOption = option.sessionOption;
|
|
593
|
-
setInterval(async () => {
|
|
594
|
-
const uuids = await this.getSessionUUIDs();
|
|
595
|
-
for (const uuid of uuids) {
|
|
596
|
-
const dataSet = await this.getSessionDataSet(uuid);
|
|
597
|
-
if (dataSet && this.isExpired(dataSet.access)) {
|
|
598
|
-
await this.deleteSession(uuid);
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
}, this.sessionOption.expiredTime);
|
|
602
|
-
}
|
|
603
|
-
async getSessionUUIDs() {
|
|
604
|
-
if (this.sessionOption.provider?.uuids) {
|
|
605
|
-
return this.sessionOption.provider.uuids();
|
|
606
|
-
} else {
|
|
607
|
-
return Array.from(this.sessions.keys());
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
async deleteSession(uuid) {
|
|
611
|
-
if (this.sessionOption.provider?.delete) {
|
|
612
|
-
this.sessionOption.provider.delete(uuid);
|
|
613
|
-
} else {
|
|
614
|
-
this.sessions.delete(uuid);
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
async getSessionDataSet(uuid) {
|
|
618
|
-
if (this.sessionOption.provider?.get) {
|
|
619
|
-
return this.sessionOption.provider.get(uuid);
|
|
620
|
-
} else {
|
|
621
|
-
return this.sessions.get(uuid);
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
async setSessionDataSet(uuid, dataSet) {
|
|
625
|
-
if (this.sessionOption.provider?.set) {
|
|
626
|
-
this.sessionOption.provider.set(uuid, dataSet);
|
|
627
|
-
} else {
|
|
628
|
-
this.sessions.set(uuid, dataSet);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
isExpired(access, now = Date.now()) {
|
|
632
|
-
return now - access >= this.option.sessionOption.expiredTime;
|
|
633
|
-
}
|
|
634
|
-
makeUUID() {
|
|
635
|
-
return import_RandomUtils.RandomUtils.uuid("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
|
|
636
|
-
}
|
|
637
|
-
async session(rrOrUUID) {
|
|
638
|
-
let uuid;
|
|
639
|
-
if (rrOrUUID instanceof RequestResponse) {
|
|
640
|
-
uuid = rrOrUUID.reqCookieGet(this.sessionOption.key) ?? this.makeUUID();
|
|
641
|
-
} else if (typeof rrOrUUID === "string") {
|
|
642
|
-
uuid = rrOrUUID;
|
|
643
|
-
} else {
|
|
644
|
-
uuid = this.makeUUID();
|
|
645
|
-
}
|
|
646
|
-
let dataSet = await this.getSessionDataSet(uuid);
|
|
647
|
-
const now = Date.now();
|
|
648
|
-
if (dataSet) {
|
|
649
|
-
if (this.isExpired(dataSet.access, now)) {
|
|
650
|
-
delete dataSet.data;
|
|
651
|
-
}
|
|
652
|
-
dataSet.access = now;
|
|
653
|
-
} else {
|
|
654
|
-
dataSet = {
|
|
655
|
-
access: now
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
await this.setSessionDataSet(uuid, dataSet);
|
|
659
|
-
return { uuid, dataSet };
|
|
660
|
-
}
|
|
661
|
-
};
|
|
662
|
-
|
|
663
|
-
// src/inject/InjectSituationType.ts
|
|
664
|
-
var InjectSituationType;
|
|
665
|
-
((InjectSituationType2) => {
|
|
666
|
-
InjectSituationType2.TransactionManager = Symbol("TransactionManager");
|
|
667
|
-
})(InjectSituationType || (InjectSituationType = {}));
|
|
668
|
-
|
|
669
|
-
// src/SimpleBootHttpServer.ts
|
|
670
|
-
var SimpleBootHttpServer = class extends import_SimpleApplication.SimpleApplication {
|
|
671
|
-
constructor(option = new HttpServerOption()) {
|
|
44
|
+
var import_url = require("url");
|
|
45
|
+
var import_HttpMethod = require("./codes/HttpMethod");
|
|
46
|
+
var import_SessionManager = require("./session/SessionManager");
|
|
47
|
+
var import_InjectSituationType = require("./inject/InjectSituationType");
|
|
48
|
+
class SimpleBootHttpServer extends import_SimpleApplication.SimpleApplication {
|
|
49
|
+
constructor(option = new import_HttpServerOption.HttpServerOption()) {
|
|
672
50
|
super(option);
|
|
673
51
|
this.option = option;
|
|
674
|
-
this.sessionManager = new SessionManager(this.option);
|
|
52
|
+
this.sessionManager = new import_SessionManager.SessionManager(this.option);
|
|
675
53
|
}
|
|
54
|
+
server;
|
|
55
|
+
sessionManager;
|
|
676
56
|
run(otherInstanceSim) {
|
|
677
57
|
const simstanceManager = super.run(otherInstanceSim);
|
|
678
58
|
const targets = [...this.option.closeEndPoints ?? [], ...this.option.errorEndPoints ?? [], ...this.option.requestEndPoints ?? [], ...this.option.filters ?? []];
|
|
@@ -733,15 +113,15 @@ var SimpleBootHttpServer = class extends import_SimpleApplication.SimpleApplicat
|
|
|
733
113
|
rr.resEnd();
|
|
734
114
|
}
|
|
735
115
|
});
|
|
736
|
-
const rr = new RequestResponse(req, res, { sessionManager: this.sessionManager, option: this.option });
|
|
737
|
-
rr.resSetHeader(
|
|
116
|
+
const rr = new import_RequestResponse.RequestResponse(req, res, { sessionManager: this.sessionManager, option: this.option });
|
|
117
|
+
rr.resSetHeader(import_HttpHeaders.HttpHeaders.Server, "simple-boot-http-server");
|
|
738
118
|
const cookie = rr.reqCookieGet(this.option.sessionOption.key);
|
|
739
119
|
if (!cookie) {
|
|
740
120
|
const session = await this.sessionManager.session();
|
|
741
|
-
rr.resSetHeader(
|
|
121
|
+
rr.resSetHeader(import_HttpHeaders.HttpHeaders.SetCookie, `${this.option.sessionOption.key}=${session.uuid}; Path=/; HttpOnly`);
|
|
742
122
|
}
|
|
743
123
|
const otherStorage = /* @__PURE__ */ new Map();
|
|
744
|
-
otherStorage.set(RequestResponse, rr);
|
|
124
|
+
otherStorage.set(import_RequestResponse.RequestResponse, rr);
|
|
745
125
|
otherStorage.set(import_http.IncomingMessage, req);
|
|
746
126
|
otherStorage.set(import_http.ServerResponse, res);
|
|
747
127
|
try {
|
|
@@ -779,15 +159,15 @@ var SimpleBootHttpServer = class extends import_SimpleApplication.SimpleApplicat
|
|
|
779
159
|
if (routerModule && moduleInstance) {
|
|
780
160
|
if (routerModule.propertyKeys) {
|
|
781
161
|
const map = routerModule.propertyKeys?.map((it) => {
|
|
782
|
-
return { propertyKey: it, config: getUrlMapping(moduleInstance, it) };
|
|
162
|
+
return { propertyKey: it, config: (0, import_MethodMapping.getUrlMapping)(moduleInstance, it) };
|
|
783
163
|
});
|
|
784
164
|
methods.push(...map ?? []);
|
|
785
165
|
} else {
|
|
786
|
-
methods.push(...getUrlMappings(moduleInstance).filter((it) => !(0, import_Router.getRoute)(moduleInstance, it.propertyKey)) ?? []);
|
|
166
|
+
methods.push(...(0, import_MethodMapping.getUrlMappings)(moduleInstance).filter((it) => !(0, import_Router.getRoute)(moduleInstance, it.propertyKey)) ?? []);
|
|
787
167
|
}
|
|
788
|
-
if (rr.reqMethod()?.toUpperCase() ===
|
|
789
|
-
rr.resSetHeader(
|
|
790
|
-
rr.resStatusCode(
|
|
168
|
+
if (rr.reqMethod()?.toUpperCase() === import_HttpMethod.HttpMethod.OPTIONS.toUpperCase()) {
|
|
169
|
+
rr.resSetHeader(import_HttpHeaders.HttpHeaders.Allow, methods.map((it) => it.config.method).join(", "));
|
|
170
|
+
rr.resStatusCode(import_HttpStatus.HttpStatus.Ok);
|
|
791
171
|
}
|
|
792
172
|
methods = methods.filter((it) => it && it.propertyKey && it.config && rr.reqMethod()?.toUpperCase() === it.config.method.toUpperCase());
|
|
793
173
|
methods.sort((a, b) => {
|
|
@@ -796,13 +176,13 @@ var SimpleBootHttpServer = class extends import_SimpleApplication.SimpleApplicat
|
|
|
796
176
|
methods = methods.filter((it) => it.config?.req?.contentType ? !!it.config?.req?.contentType?.find((sit) => rr.reqHasContentTypeHeader(sit)) : true).filter((it) => it.config?.req?.accept ? !!it.config?.req?.accept?.find((sit) => rr.reqHasAcceptHeader(sit)) : true);
|
|
797
177
|
if (methods[0]) {
|
|
798
178
|
const it = methods[0];
|
|
799
|
-
const paramTypes =
|
|
179
|
+
const paramTypes = import_ReflectUtils.ReflectUtils.getParameterTypes(moduleInstance, it.propertyKey);
|
|
800
180
|
const injects = (0, import_Inject.getInject)(moduleInstance, it.propertyKey);
|
|
801
181
|
const validIndexs = (0, import_Validation.getValidIndex)(moduleInstance, it.propertyKey);
|
|
802
182
|
if (injects) {
|
|
803
|
-
const isJson = injects.find((it2) => it2.config?.situationType ===
|
|
804
|
-
const isFormUrl = injects.find((it2) => it2.config?.situationType ===
|
|
805
|
-
const isTransactionManager = injects.find((it2) => it2.config?.situationType === InjectSituationType.TransactionManager);
|
|
183
|
+
const isJson = injects.find((it2) => it2.config?.situationType === import_MethodMapping.UrlMappingSituationType.REQ_JSON_BODY);
|
|
184
|
+
const isFormUrl = injects.find((it2) => it2.config?.situationType === import_MethodMapping.UrlMappingSituationType.REQ_FORM_URL_BODY);
|
|
185
|
+
const isTransactionManager = injects.find((it2) => it2.config?.situationType === import_InjectSituationType.InjectSituationType.TransactionManager);
|
|
806
186
|
const siturationContainers = new import_Inject.SituationTypeContainers();
|
|
807
187
|
if (isJson) {
|
|
808
188
|
let data2 = await rr.reqBodyJsonData();
|
|
@@ -816,7 +196,7 @@ var SimpleBootHttpServer = class extends import_SimpleApplication.SimpleApplicat
|
|
|
816
196
|
}
|
|
817
197
|
}
|
|
818
198
|
siturationContainers.push(new import_Inject.SituationTypeContainer({
|
|
819
|
-
situationType:
|
|
199
|
+
situationType: import_MethodMapping.UrlMappingSituationType.REQ_JSON_BODY,
|
|
820
200
|
data: data2
|
|
821
201
|
}));
|
|
822
202
|
}
|
|
@@ -831,13 +211,13 @@ var SimpleBootHttpServer = class extends import_SimpleApplication.SimpleApplicat
|
|
|
831
211
|
throw new import_ValidException.ValidException(inValid);
|
|
832
212
|
}
|
|
833
213
|
}
|
|
834
|
-
siturationContainers.push(new import_Inject.SituationTypeContainer({ situationType:
|
|
214
|
+
siturationContainers.push(new import_Inject.SituationTypeContainer({ situationType: import_MethodMapping.UrlMappingSituationType.REQ_FORM_URL_BODY, data: data2 }));
|
|
835
215
|
}
|
|
836
216
|
if (isTransactionManager && isTransactionManager.type && transactionManager && transactionManager.hasTransaction(isTransactionManager.type)) {
|
|
837
217
|
let data2 = await transactionManager.getTransaction(isTransactionManager.type);
|
|
838
218
|
if (data2) {
|
|
839
219
|
data2 = await data2.try(isTransactionManager.config.argument);
|
|
840
|
-
siturationContainers.push(new import_Inject.SituationTypeContainer({ situationType: InjectSituationType.TransactionManager, data: data2, index: isTransactionManager.index }));
|
|
220
|
+
siturationContainers.push(new import_Inject.SituationTypeContainer({ situationType: import_InjectSituationType.InjectSituationType.TransactionManager, data: data2, index: isTransactionManager.index }));
|
|
841
221
|
}
|
|
842
222
|
}
|
|
843
223
|
if (siturationContainers.length) {
|
|
@@ -845,16 +225,16 @@ var SimpleBootHttpServer = class extends import_SimpleApplication.SimpleApplicat
|
|
|
845
225
|
}
|
|
846
226
|
}
|
|
847
227
|
for (const paramType of paramTypes) {
|
|
848
|
-
if (paramType === ReqFormUrlBody) {
|
|
849
|
-
otherStorage.set(ReqFormUrlBody, await rr.reqBodyReqFormUrlBody());
|
|
850
|
-
} else if (paramType === ReqJsonBody) {
|
|
851
|
-
otherStorage.set(ReqJsonBody, await rr.reqBodyReqJsonBody());
|
|
852
|
-
} else if (paramType ===
|
|
853
|
-
otherStorage.set(
|
|
854
|
-
} else if (paramType === ReqMultipartFormBody) {
|
|
855
|
-
otherStorage.set(ReqMultipartFormBody, rr.reqBodyMultipartFormData());
|
|
856
|
-
} else if (paramType === ReqHeader) {
|
|
857
|
-
otherStorage.set(ReqHeader, rr.reqHeaderObj);
|
|
228
|
+
if (paramType === import_ReqFormUrlBody.ReqFormUrlBody) {
|
|
229
|
+
otherStorage.set(import_ReqFormUrlBody.ReqFormUrlBody, await rr.reqBodyReqFormUrlBody());
|
|
230
|
+
} else if (paramType === import_ReqJsonBody.ReqJsonBody) {
|
|
231
|
+
otherStorage.set(import_ReqJsonBody.ReqJsonBody, await rr.reqBodyReqJsonBody());
|
|
232
|
+
} else if (paramType === import_url.URLSearchParams) {
|
|
233
|
+
otherStorage.set(import_url.URLSearchParams, rr.reqUrlSearchParams);
|
|
234
|
+
} else if (paramType === import_ReqMultipartFormBody.ReqMultipartFormBody) {
|
|
235
|
+
otherStorage.set(import_ReqMultipartFormBody.ReqMultipartFormBody, rr.reqBodyMultipartFormData());
|
|
236
|
+
} else if (paramType === import_ReqHeader.ReqHeader) {
|
|
237
|
+
otherStorage.set(import_ReqHeader.ReqHeader, rr.reqHeaderObj);
|
|
858
238
|
}
|
|
859
239
|
}
|
|
860
240
|
let data = await this.simstanceManager.executeBindParameterSimPromise({
|
|
@@ -865,12 +245,12 @@ var SimpleBootHttpServer = class extends import_SimpleApplication.SimpleApplicat
|
|
|
865
245
|
const execute = typeof it.config.resolver === "function" ? this.simstanceManager.getOrNewSim({ target: it.config.resolver }) : it.config.resolver;
|
|
866
246
|
data = await execute?.resolve?.(data, rr);
|
|
867
247
|
}
|
|
868
|
-
const status = it.config?.res?.status ??
|
|
248
|
+
const status = it.config?.res?.status ?? import_HttpStatus.HttpStatus.Ok;
|
|
869
249
|
const headers = it.config?.res?.header ?? {};
|
|
870
250
|
if (it.config?.res?.contentType) {
|
|
871
|
-
headers[
|
|
251
|
+
headers[import_HttpHeaders.HttpHeaders.ContentType] = it.config?.res?.contentType;
|
|
872
252
|
}
|
|
873
|
-
if ((it.config?.res?.contentType?.toLowerCase().indexOf(
|
|
253
|
+
if ((it.config?.res?.contentType?.toLowerCase().indexOf(import_Mimes.Mimes.ApplicationJson.toLowerCase()) ?? -1) > -1) {
|
|
874
254
|
data = JSON.stringify(data);
|
|
875
255
|
} else if (data && typeof data === "object") {
|
|
876
256
|
data = JSON.stringify(data);
|
|
@@ -880,7 +260,7 @@ var SimpleBootHttpServer = class extends import_SimpleApplication.SimpleApplicat
|
|
|
880
260
|
rr.resWrite(data);
|
|
881
261
|
}
|
|
882
262
|
}
|
|
883
|
-
if (this.option.noSuchRouteEndPointMappingThrow && methods.length <= 0 && rr.reqMethod()?.toUpperCase() !==
|
|
263
|
+
if (this.option.noSuchRouteEndPointMappingThrow && methods.length <= 0 && rr.reqMethod()?.toUpperCase() !== import_HttpMethod.HttpMethod.OPTIONS) {
|
|
884
264
|
throw this.option.noSuchRouteEndPointMappingThrow(rr);
|
|
885
265
|
}
|
|
886
266
|
}
|
|
@@ -891,7 +271,7 @@ var SimpleBootHttpServer = class extends import_SimpleApplication.SimpleApplicat
|
|
|
891
271
|
}
|
|
892
272
|
} catch (e) {
|
|
893
273
|
transactionManager?.catch(e);
|
|
894
|
-
rr.resStatusCode(e instanceof HttpError ? e.status :
|
|
274
|
+
rr.resStatusCode(e instanceof import_HttpError.HttpError ? e.status : import_HttpStatus.HttpStatus.InternalServerError);
|
|
895
275
|
const execute = typeof this.option.globalAdvice === "function" ? this.simstanceManager.getOrNewSim(this.option.globalAdvice) : this.option.globalAdvice;
|
|
896
276
|
if (!execute) {
|
|
897
277
|
rr.resEnd();
|
|
@@ -922,7 +302,7 @@ var SimpleBootHttpServer = class extends import_SimpleApplication.SimpleApplicat
|
|
|
922
302
|
this.option.listen.listeningListener?.(this, this.server);
|
|
923
303
|
});
|
|
924
304
|
}
|
|
925
|
-
}
|
|
305
|
+
}
|
|
926
306
|
// Annotate the CommonJS export names for ESM import in node:
|
|
927
307
|
0 && (module.exports = {
|
|
928
308
|
SimpleBootHttpServer
|