tezx 1.0.13 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -3
- package/{dist/cjs → cjs}/index.js +1 -1
- package/{dist/index.js → index.js} +1 -1
- package/package.json +18 -19
- package/dist/MiddlewareConfigure.d.ts +0 -17
- package/dist/MiddlewareConfigure.js +0 -63
- package/dist/adapter.d.ts +0 -10
- package/dist/adapter.js +0 -162
- package/dist/cjs/MiddlewareConfigure.js +0 -68
- package/dist/cjs/adapter.js +0 -166
- package/dist/cjs/common.js +0 -15
- package/dist/cjs/config/config.js +0 -35
- package/dist/cjs/context.js +0 -428
- package/dist/cjs/environment.js +0 -34
- package/dist/cjs/header.js +0 -85
- package/dist/cjs/helper/common.js +0 -11
- package/dist/cjs/helper/env-parser.js +0 -69
- package/dist/cjs/helper/index.js +0 -20
- package/dist/cjs/middleware/cors.js +0 -49
- package/dist/cjs/middleware/index.js +0 -26
- package/dist/cjs/middleware/logger.js +0 -21
- package/dist/cjs/middleware/powered-by.js +0 -10
- package/dist/cjs/middleware/rateLimiter.js +0 -40
- package/dist/cjs/middleware/request-id.js +0 -15
- package/dist/cjs/middleware/sanitizeHeader.js +0 -51
- package/dist/cjs/middleware/secureHeaders.js +0 -42
- package/dist/cjs/middleware/xssProtection.js +0 -26
- package/dist/cjs/request.js +0 -80
- package/dist/cjs/router.js +0 -377
- package/dist/cjs/server.js +0 -170
- package/dist/cjs/utils/colors.js +0 -24
- package/dist/cjs/utils/debugging.js +0 -17
- package/dist/cjs/utils/formData.js +0 -219
- package/dist/cjs/utils/params.js +0 -94
- package/dist/cjs/utils/state.js +0 -34
- package/dist/cjs/utils/staticFile.js +0 -158
- package/dist/cjs/utils/url.js +0 -59
- package/dist/common.d.ts +0 -21
- package/dist/common.js +0 -11
- package/dist/config/config.d.ts +0 -17
- package/dist/config/config.js +0 -31
- package/dist/context.d.ts +0 -195
- package/dist/context.js +0 -424
- package/dist/environment.d.ts +0 -6
- package/dist/environment.js +0 -30
- package/dist/header.d.ts +0 -71
- package/dist/header.js +0 -81
- package/dist/helper/common.d.ts +0 -5
- package/dist/helper/common.js +0 -8
- package/dist/helper/env-parser.d.ts +0 -5
- package/dist/helper/env-parser.js +0 -66
- package/dist/helper/index.d.ts +0 -2
- package/dist/helper/index.js +0 -2
- package/dist/middleware/cors.d.ts +0 -10
- package/dist/middleware/cors.js +0 -46
- package/dist/middleware/index.d.ts +0 -9
- package/dist/middleware/index.js +0 -8
- package/dist/middleware/logger.d.ts +0 -15
- package/dist/middleware/logger.js +0 -18
- package/dist/middleware/powered-by.d.ts +0 -16
- package/dist/middleware/powered-by.js +0 -6
- package/dist/middleware/rateLimiter.d.ts +0 -61
- package/dist/middleware/rateLimiter.js +0 -36
- package/dist/middleware/request-id.d.ts +0 -16
- package/dist/middleware/request-id.js +0 -11
- package/dist/middleware/sanitizeHeader.d.ts +0 -53
- package/dist/middleware/sanitizeHeader.js +0 -47
- package/dist/middleware/secureHeaders.d.ts +0 -78
- package/dist/middleware/secureHeaders.js +0 -38
- package/dist/middleware/xssProtection.d.ts +0 -43
- package/dist/middleware/xssProtection.js +0 -22
- package/dist/request.d.ts +0 -82
- package/dist/request.js +0 -76
- package/dist/router.d.ts +0 -191
- package/dist/router.js +0 -373
- package/dist/server.d.ts +0 -54
- package/dist/server.js +0 -166
- package/dist/utils/colors.d.ts +0 -21
- package/dist/utils/colors.js +0 -21
- package/dist/utils/debugging.d.ts +0 -7
- package/dist/utils/debugging.js +0 -13
- package/dist/utils/formData.d.ts +0 -5
- package/dist/utils/formData.js +0 -213
- package/dist/utils/params.d.ts +0 -7
- package/dist/utils/params.js +0 -91
- package/dist/utils/state.d.ts +0 -50
- package/dist/utils/state.js +0 -30
- package/dist/utils/staticFile.d.ts +0 -9
- package/dist/utils/staticFile.js +0 -154
- package/dist/utils/url.d.ts +0 -16
- package/dist/utils/url.js +0 -55
- /package/{dist/index.d.ts → index.d.ts} +0 -0
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseJsonBody = parseJsonBody;
|
|
4
|
-
exports.parseTextBody = parseTextBody;
|
|
5
|
-
exports.parseUrlEncodedBody = parseUrlEncodedBody;
|
|
6
|
-
exports.parseMultipartBody = parseMultipartBody;
|
|
7
|
-
const environment_1 = require("../environment");
|
|
8
|
-
async function parseJsonBody(req) {
|
|
9
|
-
const runtime = environment_1.EnvironmentDetector.getEnvironment;
|
|
10
|
-
if (runtime === "node") {
|
|
11
|
-
return new Promise((resolve, reject) => {
|
|
12
|
-
let body = "";
|
|
13
|
-
req.on("data", (chunk) => {
|
|
14
|
-
body += chunk.toString();
|
|
15
|
-
});
|
|
16
|
-
req.on("end", () => {
|
|
17
|
-
try {
|
|
18
|
-
resolve(JSON.parse(body));
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
reject(new Error("Invalid JSON format"));
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
else if (runtime === "deno" || runtime === "bun") {
|
|
27
|
-
return await req.json();
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
throw new Error("Unsupported environment for multipart parsing");
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async function parseTextBody(req) {
|
|
34
|
-
const runtime = environment_1.EnvironmentDetector.getEnvironment;
|
|
35
|
-
if (runtime === "node") {
|
|
36
|
-
return new Promise((resolve, reject) => {
|
|
37
|
-
let body = "";
|
|
38
|
-
req.on("data", (chunk) => {
|
|
39
|
-
body += chunk.toString();
|
|
40
|
-
});
|
|
41
|
-
req.on("end", () => {
|
|
42
|
-
try {
|
|
43
|
-
resolve(body);
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
reject(new Error("Invalid JSON format"));
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
else if (runtime === "deno" || runtime === "bun") {
|
|
52
|
-
return await req.text();
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
throw new Error("Unsupported environment for multipart parsing");
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
async function parseUrlEncodedBody(req) {
|
|
59
|
-
const runtime = environment_1.EnvironmentDetector.getEnvironment;
|
|
60
|
-
if (runtime === "node") {
|
|
61
|
-
return new Promise((resolve, reject) => {
|
|
62
|
-
let body = "";
|
|
63
|
-
req.on("data", (chunk) => {
|
|
64
|
-
body += chunk.toString("binary");
|
|
65
|
-
});
|
|
66
|
-
req.on("end", () => {
|
|
67
|
-
try {
|
|
68
|
-
const pairs = body.split("&");
|
|
69
|
-
const formData = {};
|
|
70
|
-
pairs.forEach((pair) => {
|
|
71
|
-
const [key, value] = pair.split("=");
|
|
72
|
-
formData[decodeURIComponent(key)] = decodeURIComponent(value || "");
|
|
73
|
-
});
|
|
74
|
-
resolve(formData);
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
reject(new Error("Invalid x-www-form-urlencoded format"));
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
else if (runtime === "deno" || runtime === "bun") {
|
|
83
|
-
const formData = await req.formData();
|
|
84
|
-
const result = {};
|
|
85
|
-
for (const [key, value] of formData.entries()) {
|
|
86
|
-
result[key] = value;
|
|
87
|
-
}
|
|
88
|
-
return result;
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
throw new Error("Unsupported environment for multipart parsing");
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
async function parseMultipartBody(req, boundary, options) {
|
|
95
|
-
const runtime = environment_1.EnvironmentDetector.getEnvironment;
|
|
96
|
-
const x = options?.sanitized;
|
|
97
|
-
if (runtime === "node") {
|
|
98
|
-
return new Promise((resolve, reject) => {
|
|
99
|
-
let body = "";
|
|
100
|
-
req.on("data", (chunk) => {
|
|
101
|
-
body += chunk.toString("binary");
|
|
102
|
-
});
|
|
103
|
-
req.on("end", () => {
|
|
104
|
-
try {
|
|
105
|
-
const formDataField = {};
|
|
106
|
-
const formDataFieldParts = body.split("----------------------------");
|
|
107
|
-
formDataFieldParts.forEach((part) => {
|
|
108
|
-
const match = part.match(/name="(.*)"\r\n\r\n(.*)\r\n/);
|
|
109
|
-
if (match && match.length === 3) {
|
|
110
|
-
const name = match[1];
|
|
111
|
-
const value = match[2];
|
|
112
|
-
formDataField[name] = value;
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
const parts = body.split(`--${boundary}`);
|
|
116
|
-
for (const part of parts) {
|
|
117
|
-
if (part.includes("filename")) {
|
|
118
|
-
const filenameMatch = part.match(/filename="([^"]+)"/);
|
|
119
|
-
const fieldNameMatch = part.match(/name="([^"]+)"/);
|
|
120
|
-
const contentTypeMatch = part.match(/Content-Type: ([^\r\n]+)/);
|
|
121
|
-
if (filenameMatch && fieldNameMatch && contentTypeMatch) {
|
|
122
|
-
let filename = filenameMatch[1];
|
|
123
|
-
const fieldName = fieldNameMatch[1];
|
|
124
|
-
const contentType = contentTypeMatch[1];
|
|
125
|
-
if (options?.sanitized) {
|
|
126
|
-
filename =
|
|
127
|
-
`${Date.now()}-${filename.replace(/\s+/g, "")?.replace(/[^a-zA-Z0-9.-]/g, "-")}`?.toLowerCase();
|
|
128
|
-
}
|
|
129
|
-
if (Array.isArray(options?.allowedTypes) &&
|
|
130
|
-
!options.allowedTypes?.includes(contentType)) {
|
|
131
|
-
reject(`Invalid file type: "${contentType}". Allowed types: ${options.allowedTypes.join(", ")}`);
|
|
132
|
-
}
|
|
133
|
-
const fileContentStartIndex = part.indexOf("\r\n\r\n") + 4;
|
|
134
|
-
const fileContent = Buffer.from(part.substring(fileContentStartIndex), "binary");
|
|
135
|
-
const arrayBuffer = fileContent.buffer.slice(fileContent.byteOffset, fileContent.byteOffset + fileContent.byteLength);
|
|
136
|
-
if (typeof options?.maxSize !== "undefined" &&
|
|
137
|
-
fileContent.byteLength > options.maxSize) {
|
|
138
|
-
reject(`File size exceeds the limit: ${fileContent.byteLength} bytes (Max: ${options.maxSize} bytes)`);
|
|
139
|
-
}
|
|
140
|
-
const file = new File([arrayBuffer], filename, {
|
|
141
|
-
type: contentType,
|
|
142
|
-
});
|
|
143
|
-
if (typeof options?.maxFiles != "undefined" &&
|
|
144
|
-
options.maxFiles == 0) {
|
|
145
|
-
reject(`Field "${fieldName}" exceeds the maximum allowed file count of ${options.maxFiles}.`);
|
|
146
|
-
}
|
|
147
|
-
if (formDataField[fieldName]) {
|
|
148
|
-
if (Array.isArray(formDataField[fieldName])) {
|
|
149
|
-
if (typeof options?.maxFiles != "undefined" &&
|
|
150
|
-
formDataField[fieldName]?.length >= options.maxFiles) {
|
|
151
|
-
reject(`Field "${fieldName}" exceeds the maximum allowed file count of ${options.maxFiles}.`);
|
|
152
|
-
}
|
|
153
|
-
formDataField[fieldName].push(file);
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
formDataField[fieldName] = [formDataField[fieldName], file];
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
formDataField[fieldName] = file;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
resolve(formDataField);
|
|
166
|
-
}
|
|
167
|
-
catch { }
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
else if (runtime === "deno" || runtime === "bun") {
|
|
172
|
-
const formData = await req.formData();
|
|
173
|
-
const result = {};
|
|
174
|
-
for (const [key, value] of formData.entries()) {
|
|
175
|
-
let val = value;
|
|
176
|
-
if (val instanceof File && typeof options == "object") {
|
|
177
|
-
let filename = val.name;
|
|
178
|
-
if (options?.sanitized) {
|
|
179
|
-
filename =
|
|
180
|
-
`${Date.now()}-${filename.replace(/\s+/g, "")?.replace(/[^a-zA-Z0-9.-]/g, "-")}`?.toLowerCase();
|
|
181
|
-
}
|
|
182
|
-
if (Array.isArray(options?.allowedTypes) &&
|
|
183
|
-
!options.allowedTypes?.includes(val.type)) {
|
|
184
|
-
throw new Error(`Invalid file type: "${val.type}". Allowed types: ${options.allowedTypes.join(", ")}`);
|
|
185
|
-
}
|
|
186
|
-
if (typeof options?.maxSize !== "undefined" &&
|
|
187
|
-
val.size > options.maxSize) {
|
|
188
|
-
throw new Error(`File size exceeds the limit: ${val.size} bytes (Max: ${options.maxSize} bytes)`);
|
|
189
|
-
}
|
|
190
|
-
if (typeof options?.maxFiles != "undefined" && options.maxFiles == 0) {
|
|
191
|
-
throw new Error(`Field "${key}" exceeds the maximum allowed file count of ${options.maxFiles}.`);
|
|
192
|
-
}
|
|
193
|
-
val = new File([await val.arrayBuffer()], filename, {
|
|
194
|
-
type: val.type,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
if (result[key]) {
|
|
198
|
-
if (Array.isArray(result[key])) {
|
|
199
|
-
if (val instanceof File &&
|
|
200
|
-
typeof options?.maxFiles != "undefined" &&
|
|
201
|
-
result[key]?.length >= options.maxFiles) {
|
|
202
|
-
throw new Error(`Field "${key}" exceeds the maximum allowed file count of ${options.maxFiles}.`);
|
|
203
|
-
}
|
|
204
|
-
result[key].push(val);
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
result[key] = [result[key], val];
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
result[key] = val;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return result;
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
throw new Error("Unsupported environment for multipart parsing");
|
|
218
|
-
}
|
|
219
|
-
}
|
package/dist/cjs/utils/params.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useParams = useParams;
|
|
4
|
-
function useParams({ path, urlPattern, }) {
|
|
5
|
-
let params = {};
|
|
6
|
-
path = path.replace(/^\/+|\/+$/g, "");
|
|
7
|
-
urlPattern = urlPattern.replace(/^\/+|\/+$/g, "");
|
|
8
|
-
const pathSegments = path ? path.split("/") : [];
|
|
9
|
-
const patternSegments = urlPattern ? urlPattern.split("/") : [];
|
|
10
|
-
const pathLength = pathSegments.length;
|
|
11
|
-
const patternLength = patternSegments.length;
|
|
12
|
-
if (pathLength > patternLength && !urlPattern.includes("*")) {
|
|
13
|
-
return { success: false, params: {} };
|
|
14
|
-
}
|
|
15
|
-
let pathIndex = 0;
|
|
16
|
-
for (let i = 0; i < patternLength; i++) {
|
|
17
|
-
const patternSegment = patternSegments[i];
|
|
18
|
-
if (patternSegment?.startsWith("*")) {
|
|
19
|
-
const trailingPatterns = patternSegments.slice(i + 1);
|
|
20
|
-
let paramName = patternSegment.length == 1 ? "*" : patternSegment?.slice(1);
|
|
21
|
-
if (trailingPatterns.length > 0) {
|
|
22
|
-
const expectedTrailing = trailingPatterns.join("/");
|
|
23
|
-
const actualTrailing = pathSegments
|
|
24
|
-
.slice(pathLength - trailingPatterns.length)
|
|
25
|
-
.join("/");
|
|
26
|
-
const wildcardPath = pathSegments
|
|
27
|
-
.slice(pathIndex, pathLength - trailingPatterns.length)
|
|
28
|
-
.join("/");
|
|
29
|
-
if (expectedTrailing !== actualTrailing || !wildcardPath) {
|
|
30
|
-
return { success: false, params: {} };
|
|
31
|
-
}
|
|
32
|
-
params[paramName] = wildcardPath;
|
|
33
|
-
return { success: true, params };
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
const wildcardPath = pathSegments.slice(pathIndex).join("/");
|
|
37
|
-
if (!wildcardPath) {
|
|
38
|
-
return { success: false, params: {} };
|
|
39
|
-
}
|
|
40
|
-
params[paramName] = wildcardPath;
|
|
41
|
-
return { success: true, params };
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (patternSegment.startsWith(":") && patternSegment.endsWith("?")) {
|
|
45
|
-
const paramName = patternSegment.slice(1, -1);
|
|
46
|
-
const nextPattern = patternSegments[i + 1];
|
|
47
|
-
if (nextPattern &&
|
|
48
|
-
!nextPattern.startsWith(":") &&
|
|
49
|
-
nextPattern !== "*" &&
|
|
50
|
-
pathIndex < pathLength &&
|
|
51
|
-
pathSegments[pathIndex] === nextPattern) {
|
|
52
|
-
params[paramName] = null;
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
const remainingPatterns = patternSegments.slice(i + 1);
|
|
56
|
-
const requiredCount = remainingPatterns.filter((seg) => !(seg.startsWith(":") && seg.endsWith("?"))).length;
|
|
57
|
-
const remainingPath = pathLength - pathIndex;
|
|
58
|
-
if (remainingPath === requiredCount) {
|
|
59
|
-
params[paramName] = null;
|
|
60
|
-
}
|
|
61
|
-
else if (pathIndex < pathLength) {
|
|
62
|
-
params[paramName] = pathSegments[pathIndex];
|
|
63
|
-
pathIndex++;
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
params[paramName] = null;
|
|
67
|
-
}
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
if (patternSegment.startsWith(":")) {
|
|
71
|
-
const paramName = patternSegment.slice(1);
|
|
72
|
-
if (!/^[a-zA-Z0-9_]+$/.test(paramName)) {
|
|
73
|
-
return { success: false, params: {} };
|
|
74
|
-
}
|
|
75
|
-
if (pathIndex < pathLength) {
|
|
76
|
-
params[paramName] = pathSegments[pathIndex];
|
|
77
|
-
pathIndex++;
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
return { success: false, params: {} };
|
|
81
|
-
}
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
const pathSegment = pathSegments[pathIndex];
|
|
85
|
-
if (patternSegment !== pathSegment) {
|
|
86
|
-
return { success: false, params: {} };
|
|
87
|
-
}
|
|
88
|
-
pathIndex++;
|
|
89
|
-
}
|
|
90
|
-
if (pathIndex < pathLength) {
|
|
91
|
-
return { success: false, params: {} };
|
|
92
|
-
}
|
|
93
|
-
return { success: true, params };
|
|
94
|
-
}
|
package/dist/cjs/utils/state.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.State = void 0;
|
|
4
|
-
class State {
|
|
5
|
-
state;
|
|
6
|
-
constructor() {
|
|
7
|
-
this.state = new Map();
|
|
8
|
-
}
|
|
9
|
-
set(key, value) {
|
|
10
|
-
this.state.set(key, value);
|
|
11
|
-
}
|
|
12
|
-
get(key) {
|
|
13
|
-
return this.state.get(key);
|
|
14
|
-
}
|
|
15
|
-
delete(key) {
|
|
16
|
-
return this.state.delete(key);
|
|
17
|
-
}
|
|
18
|
-
has(key) {
|
|
19
|
-
return this.state.has(key);
|
|
20
|
-
}
|
|
21
|
-
keys() {
|
|
22
|
-
return Array.from(this.state.keys());
|
|
23
|
-
}
|
|
24
|
-
values() {
|
|
25
|
-
return Array.from(this.state.values());
|
|
26
|
-
}
|
|
27
|
-
entries() {
|
|
28
|
-
return Array.from(this.state.entries());
|
|
29
|
-
}
|
|
30
|
-
clear() {
|
|
31
|
-
this.state.clear();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.State = State;
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultMimeType = exports.mimeTypes = void 0;
|
|
4
|
-
exports.getFiles = getFiles;
|
|
5
|
-
const environment_1 = require("../environment");
|
|
6
|
-
exports.mimeTypes = {
|
|
7
|
-
html: "text/html",
|
|
8
|
-
htm: "text/html",
|
|
9
|
-
css: "text/css",
|
|
10
|
-
js: "text/javascript",
|
|
11
|
-
mjs: "text/javascript",
|
|
12
|
-
json: "application/json",
|
|
13
|
-
xml: "application/xml",
|
|
14
|
-
txt: "text/plain",
|
|
15
|
-
md: "text/markdown",
|
|
16
|
-
csv: "text/csv",
|
|
17
|
-
tsv: "text/tab-separated-values",
|
|
18
|
-
rtf: "application/rtf",
|
|
19
|
-
markdown: "text/markdown",
|
|
20
|
-
png: "image/png",
|
|
21
|
-
jpg: "image/jpeg",
|
|
22
|
-
jpeg: "image/jpeg",
|
|
23
|
-
gif: "image/gif",
|
|
24
|
-
svg: "image/svg+xml",
|
|
25
|
-
webp: "image/webp",
|
|
26
|
-
ico: "image/x-icon",
|
|
27
|
-
bmp: "image/bmp",
|
|
28
|
-
tiff: "image/tiff",
|
|
29
|
-
psd: "image/vnd.adobe.photoshop",
|
|
30
|
-
mp4: "video/mp4",
|
|
31
|
-
webm: "video/webm",
|
|
32
|
-
ogg: "video/ogg",
|
|
33
|
-
mov: "video/quicktime",
|
|
34
|
-
avi: "video/x-msvideo",
|
|
35
|
-
wmv: "video/x-ms-wmv",
|
|
36
|
-
flv: "video/x-flv",
|
|
37
|
-
"3gp": "video/3gpp",
|
|
38
|
-
mp3: "audio/mpeg",
|
|
39
|
-
wav: "audio/wav",
|
|
40
|
-
aac: "audio/aac",
|
|
41
|
-
flac: "audio/flac",
|
|
42
|
-
m4a: "audio/mp4",
|
|
43
|
-
mid: "audio/midi",
|
|
44
|
-
midi: "audio/midi",
|
|
45
|
-
woff: "font/woff",
|
|
46
|
-
woff2: "font/woff2",
|
|
47
|
-
ttf: "font/ttf",
|
|
48
|
-
otf: "font/otf",
|
|
49
|
-
eot: "application/vnd.ms-fontobject",
|
|
50
|
-
pdf: "application/pdf",
|
|
51
|
-
odp: "application/vnd.oasis.opendocument.presentation",
|
|
52
|
-
zip: "application/zip",
|
|
53
|
-
gz: "application/gzip",
|
|
54
|
-
tar: "application/x-tar",
|
|
55
|
-
rar: "application/x-rar-compressed",
|
|
56
|
-
_7z: "application/x-7z-compressed",
|
|
57
|
-
bz2: "application/x-bzip2",
|
|
58
|
-
"7z": "application/x-7z-compressed",
|
|
59
|
-
doc: "application/msword",
|
|
60
|
-
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
61
|
-
xls: "application/vnd.ms-excel",
|
|
62
|
-
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
63
|
-
ppt: "application/vnd.ms-powerpoint",
|
|
64
|
-
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
65
|
-
odt: "application/vnd.oasis.opendocument.text",
|
|
66
|
-
ods: "application/vnd.oasis.opendocument.spreadsheet",
|
|
67
|
-
wasm: "application/wasm",
|
|
68
|
-
map: "application/json",
|
|
69
|
-
yaml: "application/yaml",
|
|
70
|
-
yml: "application/yaml",
|
|
71
|
-
proto: "text/plain",
|
|
72
|
-
graphql: "application/graphql",
|
|
73
|
-
pem: "application/x-pem-file",
|
|
74
|
-
cer: "application/pkix-cert",
|
|
75
|
-
crt: "application/x-x509-ca-cert",
|
|
76
|
-
key: "application/x-pem-file",
|
|
77
|
-
pfx: "application/x-pkcs12",
|
|
78
|
-
glb: "model/gltf-binary",
|
|
79
|
-
gltf: "model/gltf+json",
|
|
80
|
-
obj: "model/obj",
|
|
81
|
-
stl: "model/stl",
|
|
82
|
-
usdz: "model/vnd.usdz+zip",
|
|
83
|
-
exe: "application/x-msdownload",
|
|
84
|
-
dmg: "application/x-apple-diskimage",
|
|
85
|
-
deb: "application/x-debian-package",
|
|
86
|
-
rpm: "application/x-redhat-package-manager",
|
|
87
|
-
apk: "application/vnd.android.package-archive",
|
|
88
|
-
webmanifest: "application/manifest+json",
|
|
89
|
-
ics: "text/calendar",
|
|
90
|
-
vcf: "text/vcard",
|
|
91
|
-
warc: "application/warc",
|
|
92
|
-
atom: "application/atom+xml",
|
|
93
|
-
rss: "application/rss+xml",
|
|
94
|
-
dll: "application/x-msdownload",
|
|
95
|
-
sh: "application/x-sh",
|
|
96
|
-
py: "text/x-python",
|
|
97
|
-
rb: "text/x-ruby",
|
|
98
|
-
pl: "text/x-perl",
|
|
99
|
-
php: "application/x-httpd-php",
|
|
100
|
-
torrent: "application/x-bittorrent",
|
|
101
|
-
ipa: "application/vnd.iphone",
|
|
102
|
-
eps: "application/postscript",
|
|
103
|
-
ps: "application/postscript",
|
|
104
|
-
ai: "application/postscript",
|
|
105
|
-
swf: "application/x-shockwave-flash",
|
|
106
|
-
jar: "application/java-archive",
|
|
107
|
-
gcode: "text/x.gcode",
|
|
108
|
-
};
|
|
109
|
-
exports.defaultMimeType = "application/octet-stream";
|
|
110
|
-
async function getFiles(dir, basePath = "/", ref, option) {
|
|
111
|
-
const files = [];
|
|
112
|
-
const runtime = environment_1.EnvironmentDetector.getEnvironment;
|
|
113
|
-
if (runtime == "deno") {
|
|
114
|
-
for await (const entry of Deno.readDir(dir)) {
|
|
115
|
-
const path = `${dir}/${entry.name}`;
|
|
116
|
-
if (entry.isDirectory) {
|
|
117
|
-
files.push(...(await getFiles(path, `${basePath}/${entry.name}`, ref, option)));
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
const x = `${basePath}/${entry.name}`;
|
|
121
|
-
files.push({
|
|
122
|
-
file: path,
|
|
123
|
-
path: x.replace(/\\/g, "/"),
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
const fs = await Promise.resolve().then(() => require("fs/promises"));
|
|
130
|
-
const path = await Promise.resolve().then(() => require("path"));
|
|
131
|
-
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
132
|
-
for (const entry of entries) {
|
|
133
|
-
const fullPath = path.join(dir, entry.name);
|
|
134
|
-
if (entry.isDirectory()) {
|
|
135
|
-
files.push(...(await getFiles(fullPath, `${basePath}/${entry.name}`, ref, option)));
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
const path = `${basePath}/${entry.name}`;
|
|
139
|
-
files.push({
|
|
140
|
-
file: fullPath,
|
|
141
|
-
path: path.replace(/\\/g, "/"),
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
files.forEach((r) => {
|
|
147
|
-
ref.get(r.path, (ctx) => {
|
|
148
|
-
if (option.cacheControl) {
|
|
149
|
-
ctx.headers.set("Cache-Control", option.cacheControl);
|
|
150
|
-
}
|
|
151
|
-
if (option.headers) {
|
|
152
|
-
ctx.headers.add(option.headers);
|
|
153
|
-
}
|
|
154
|
-
return ctx.sendFile(r.file);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
return files;
|
|
158
|
-
}
|
package/dist/cjs/utils/url.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sanitizePathSplit = sanitizePathSplit;
|
|
4
|
-
exports.urlParse = urlParse;
|
|
5
|
-
function sanitizePathSplit(basePath, path) {
|
|
6
|
-
const parts = `${basePath}/${path}`
|
|
7
|
-
.replace(/\\/g, "")
|
|
8
|
-
?.split("/")
|
|
9
|
-
.filter(Boolean);
|
|
10
|
-
return parts;
|
|
11
|
-
}
|
|
12
|
-
function urlParse(url) {
|
|
13
|
-
const urlPattern = /^(?:(\w+):\/\/)?(?:([^:@]+)?(?::([^@]+))?@)?([^:/?#]+)?(?::(\d+))?(\/[^?#]*)?(?:\?([^#]*))?(?:#(.*))?$/;
|
|
14
|
-
let matches = url.match(urlPattern);
|
|
15
|
-
if (!matches) {
|
|
16
|
-
href: url;
|
|
17
|
-
}
|
|
18
|
-
const [_, protocol, username, password, hostname, port, path, queryString, hash,] = matches;
|
|
19
|
-
let origin = hostname;
|
|
20
|
-
if (protocol) {
|
|
21
|
-
origin = protocol + "://" + hostname;
|
|
22
|
-
}
|
|
23
|
-
if (port) {
|
|
24
|
-
origin = origin + ":" + port;
|
|
25
|
-
}
|
|
26
|
-
let p = path;
|
|
27
|
-
if (p?.endsWith("/"))
|
|
28
|
-
p.slice(0, -1);
|
|
29
|
-
function query() {
|
|
30
|
-
if (queryString) {
|
|
31
|
-
const queryPart = decodeURIComponent(queryString);
|
|
32
|
-
const keyValuePairs = queryPart.split("&");
|
|
33
|
-
const paramsObj = keyValuePairs?.map((keyValue) => {
|
|
34
|
-
const [key, value] = keyValue.split("=");
|
|
35
|
-
return {
|
|
36
|
-
[key]: value,
|
|
37
|
-
};
|
|
38
|
-
});
|
|
39
|
-
return paramsObj.reduce(function (total, value) {
|
|
40
|
-
return { ...total, ...value };
|
|
41
|
-
}, {});
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
return {};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
pathname: p,
|
|
49
|
-
hash,
|
|
50
|
-
protocol,
|
|
51
|
-
origin,
|
|
52
|
-
username,
|
|
53
|
-
password,
|
|
54
|
-
hostname,
|
|
55
|
-
href: url,
|
|
56
|
-
port,
|
|
57
|
-
query: query(),
|
|
58
|
-
};
|
|
59
|
-
}
|
package/dist/common.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Context } from "./context";
|
|
2
|
-
import { Callback, ctx } from "./router";
|
|
3
|
-
export interface option {
|
|
4
|
-
status?: number;
|
|
5
|
-
}
|
|
6
|
-
export type onError<T> = (error: string, ctx: Context) => void;
|
|
7
|
-
export declare class CommonHandler {
|
|
8
|
-
/**
|
|
9
|
-
* Register a custom 404 handler for missing routes
|
|
10
|
-
* @param {Callback} callback - Handler function to execute when no route matches
|
|
11
|
-
* @returns {this} - Returns current instance for chaining
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* // Register a custom not-found handler
|
|
15
|
-
* app.notFound((ctx) => {
|
|
16
|
-
* ctx.status(404).text('Custom not found message');
|
|
17
|
-
* });
|
|
18
|
-
*/
|
|
19
|
-
notFound(callback: Callback): this;
|
|
20
|
-
onError(callback: <T extends Record<string, any> = {}>(err: string, ctx: ctx<T>) => any): this;
|
|
21
|
-
}
|
package/dist/common.js
DELETED
package/dist/config/config.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Callback, ctx } from "../router";
|
|
2
|
-
export declare let GlobalConfig: {
|
|
3
|
-
new (): {};
|
|
4
|
-
notFound: Callback;
|
|
5
|
-
onError: <T extends Record<string, any> = {}>(err: string, ctx: ctx<T>) => any;
|
|
6
|
-
allowDuplicateMw?: boolean;
|
|
7
|
-
overwriteMethod?: boolean;
|
|
8
|
-
debugMode?: boolean;
|
|
9
|
-
serverInfo: any;
|
|
10
|
-
readonly debugging: {
|
|
11
|
-
info: (msg: string, ...args: unknown[]) => void;
|
|
12
|
-
warn: (msg: string, ...args: unknown[]) => void;
|
|
13
|
-
error: (msg: string, ...args: unknown[]) => void;
|
|
14
|
-
debug: (msg: string, ...args: unknown[]) => void;
|
|
15
|
-
success: (msg: string, ...args: unknown[]) => void;
|
|
16
|
-
};
|
|
17
|
-
};
|
package/dist/config/config.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { loggerOutput } from "../utils/debugging";
|
|
2
|
-
export let GlobalConfig = class {
|
|
3
|
-
static notFound = (ctx) => {
|
|
4
|
-
const { method, urlRef: { pathname }, } = ctx.req;
|
|
5
|
-
return ctx.text(`${method}: '${pathname}' could not find\n`, 404);
|
|
6
|
-
};
|
|
7
|
-
static onError = (err, ctx) => {
|
|
8
|
-
return ctx.text(err, 500);
|
|
9
|
-
};
|
|
10
|
-
static allowDuplicateMw = false;
|
|
11
|
-
static overwriteMethod = true;
|
|
12
|
-
static debugMode = false;
|
|
13
|
-
static serverInfo;
|
|
14
|
-
static get debugging() {
|
|
15
|
-
return this.debugMode
|
|
16
|
-
? {
|
|
17
|
-
info: (msg, ...args) => loggerOutput("info", msg, ...args),
|
|
18
|
-
warn: (msg, ...args) => loggerOutput("warn", msg, ...args),
|
|
19
|
-
error: (msg, ...args) => loggerOutput("error", msg, ...args),
|
|
20
|
-
debug: (msg, ...args) => loggerOutput("debug", msg, ...args),
|
|
21
|
-
success: (msg, ...args) => loggerOutput("success", msg, ...args),
|
|
22
|
-
}
|
|
23
|
-
: {
|
|
24
|
-
info: (msg, ...args) => { },
|
|
25
|
-
warn: (msg, ...args) => { },
|
|
26
|
-
error: (msg, ...args) => { },
|
|
27
|
-
debug: (msg, ...args) => { },
|
|
28
|
-
success: (msg, ...args) => { },
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
};
|