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