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.
Files changed (92) hide show
  1. package/README.md +8 -3
  2. package/{dist/cjs → cjs}/index.js +1 -1
  3. package/{dist/index.js → index.js} +1 -1
  4. package/package.json +18 -19
  5. package/dist/MiddlewareConfigure.d.ts +0 -17
  6. package/dist/MiddlewareConfigure.js +0 -63
  7. package/dist/adapter.d.ts +0 -10
  8. package/dist/adapter.js +0 -162
  9. package/dist/cjs/MiddlewareConfigure.js +0 -68
  10. package/dist/cjs/adapter.js +0 -166
  11. package/dist/cjs/common.js +0 -15
  12. package/dist/cjs/config/config.js +0 -35
  13. package/dist/cjs/context.js +0 -428
  14. package/dist/cjs/environment.js +0 -34
  15. package/dist/cjs/header.js +0 -85
  16. package/dist/cjs/helper/common.js +0 -11
  17. package/dist/cjs/helper/env-parser.js +0 -69
  18. package/dist/cjs/helper/index.js +0 -20
  19. package/dist/cjs/middleware/cors.js +0 -49
  20. package/dist/cjs/middleware/index.js +0 -26
  21. package/dist/cjs/middleware/logger.js +0 -21
  22. package/dist/cjs/middleware/powered-by.js +0 -10
  23. package/dist/cjs/middleware/rateLimiter.js +0 -40
  24. package/dist/cjs/middleware/request-id.js +0 -15
  25. package/dist/cjs/middleware/sanitizeHeader.js +0 -51
  26. package/dist/cjs/middleware/secureHeaders.js +0 -42
  27. package/dist/cjs/middleware/xssProtection.js +0 -26
  28. package/dist/cjs/request.js +0 -80
  29. package/dist/cjs/router.js +0 -377
  30. package/dist/cjs/server.js +0 -170
  31. package/dist/cjs/utils/colors.js +0 -24
  32. package/dist/cjs/utils/debugging.js +0 -17
  33. package/dist/cjs/utils/formData.js +0 -219
  34. package/dist/cjs/utils/params.js +0 -94
  35. package/dist/cjs/utils/state.js +0 -34
  36. package/dist/cjs/utils/staticFile.js +0 -158
  37. package/dist/cjs/utils/url.js +0 -59
  38. package/dist/common.d.ts +0 -21
  39. package/dist/common.js +0 -11
  40. package/dist/config/config.d.ts +0 -17
  41. package/dist/config/config.js +0 -31
  42. package/dist/context.d.ts +0 -195
  43. package/dist/context.js +0 -424
  44. package/dist/environment.d.ts +0 -6
  45. package/dist/environment.js +0 -30
  46. package/dist/header.d.ts +0 -71
  47. package/dist/header.js +0 -81
  48. package/dist/helper/common.d.ts +0 -5
  49. package/dist/helper/common.js +0 -8
  50. package/dist/helper/env-parser.d.ts +0 -5
  51. package/dist/helper/env-parser.js +0 -66
  52. package/dist/helper/index.d.ts +0 -2
  53. package/dist/helper/index.js +0 -2
  54. package/dist/middleware/cors.d.ts +0 -10
  55. package/dist/middleware/cors.js +0 -46
  56. package/dist/middleware/index.d.ts +0 -9
  57. package/dist/middleware/index.js +0 -8
  58. package/dist/middleware/logger.d.ts +0 -15
  59. package/dist/middleware/logger.js +0 -18
  60. package/dist/middleware/powered-by.d.ts +0 -16
  61. package/dist/middleware/powered-by.js +0 -6
  62. package/dist/middleware/rateLimiter.d.ts +0 -61
  63. package/dist/middleware/rateLimiter.js +0 -36
  64. package/dist/middleware/request-id.d.ts +0 -16
  65. package/dist/middleware/request-id.js +0 -11
  66. package/dist/middleware/sanitizeHeader.d.ts +0 -53
  67. package/dist/middleware/sanitizeHeader.js +0 -47
  68. package/dist/middleware/secureHeaders.d.ts +0 -78
  69. package/dist/middleware/secureHeaders.js +0 -38
  70. package/dist/middleware/xssProtection.d.ts +0 -43
  71. package/dist/middleware/xssProtection.js +0 -22
  72. package/dist/request.d.ts +0 -82
  73. package/dist/request.js +0 -76
  74. package/dist/router.d.ts +0 -191
  75. package/dist/router.js +0 -373
  76. package/dist/server.d.ts +0 -54
  77. package/dist/server.js +0 -166
  78. package/dist/utils/colors.d.ts +0 -21
  79. package/dist/utils/colors.js +0 -21
  80. package/dist/utils/debugging.d.ts +0 -7
  81. package/dist/utils/debugging.js +0 -13
  82. package/dist/utils/formData.d.ts +0 -5
  83. package/dist/utils/formData.js +0 -213
  84. package/dist/utils/params.d.ts +0 -7
  85. package/dist/utils/params.js +0 -91
  86. package/dist/utils/state.d.ts +0 -50
  87. package/dist/utils/state.js +0 -30
  88. package/dist/utils/staticFile.d.ts +0 -9
  89. package/dist/utils/staticFile.js +0 -154
  90. package/dist/utils/url.d.ts +0 -16
  91. package/dist/utils/url.js +0 -55
  92. /package/{dist/index.d.ts → index.d.ts} +0 -0
package/dist/context.d.ts DELETED
@@ -1,195 +0,0 @@
1
- import { HeadersParser } from "./header";
2
- import { ConnAddress, HTTPMethod, Request } from "./request";
3
- import { State } from "./utils/state";
4
- export interface CookieOptions {
5
- expires?: Date;
6
- path?: string;
7
- maxAge?: number;
8
- domain?: string;
9
- secure?: boolean;
10
- httpOnly?: boolean;
11
- sameSite?: "Strict" | "Lax" | "None";
12
- }
13
- export declare const httpStatusMap: Record<number, string>;
14
- export type ResponseHeaders = Record<string, string>;
15
- export declare class Context<T extends Record<string, any> = {}> {
16
- #private;
17
- [key: string]: any;
18
- /**
19
- * Environment variables and configuration
20
- * @type {object}
21
- */
22
- env: Record<string, any> & T;
23
- /**
24
- * Parser for handling and manipulating HTTP headers
25
- * @type {HeadersParser}
26
- */
27
- headers: HeadersParser;
28
- /**
29
- * Parser for handling and manipulating HTTP response(Read Only)
30
- * @type {Response}
31
- */
32
- readonly res: Response | undefined;
33
- /**
34
- * Request path without query parameters
35
- * @type {string}
36
- */
37
- readonly pathname: string;
38
- /**
39
- * Full request URL including protocol and query string
40
- * @type {string}
41
- */
42
- readonly url: string;
43
- /**
44
- * HTTP request method (GET, POST, PUT, DELETE, etc.)
45
- * @type {HTTPMethod}
46
- */
47
- readonly method: HTTPMethod;
48
- /**
49
- * Public state container for application data
50
- * state storage for middleware and plugins
51
- * @type {State}
52
- */
53
- state: State;
54
- constructor(req: any, connInfo: ConnAddress);
55
- /**
56
- * Cookie handling utility with get/set/delete operations
57
- * @returns {{
58
- * get: (name: string) => string | undefined,
59
- * all: () => Record<string, string>,
60
- * delete: (name: string, options?: CookieOptions) => void,
61
- * set: (name: string, value: string, options?: CookieOptions) => void
62
- * }} Cookie handling interface
63
- */
64
- /**
65
- * Sets a header value.
66
- * @param key - Header name.
67
- * @param value - Header value(s).
68
- */
69
- header(key: string, value: string | string[]): this;
70
- get cookies(): {
71
- /**
72
- * Get a specific cookie by name.
73
- * @param {string} cookie - The name of the cookie to retrieve.
74
- * @returns {string | undefined} - The cookie value or undefined if not found.
75
- */
76
- get: (cookie: string) => string;
77
- /**
78
- * Get all cookies as an object.
79
- * @returns {Record<string, string>} - An object containing all cookies.
80
- */
81
- all: () => Record<string, string>;
82
- /**
83
- * Delete a cookie by setting its expiration to the past.
84
- * @param {string} name - The name of the cookie to delete.
85
- * @param {CookieOptions} [options] - Additional cookie options.
86
- */
87
- delete: (name: string, options?: CookieOptions) => void;
88
- /**
89
- * Set a new cookie with the given name, value, and options.
90
- * @param {string} name - The name of the cookie.
91
- * @param {string} value - The value of the cookie.
92
- * @param {CookieOptions} [options] - Additional options like expiration.
93
- */
94
- set: (name: string, value: string, options?: CookieOptions) => void;
95
- };
96
- /**
97
- * Sends a JSON response.
98
- * @param body - The response data.
99
- * @param status - (Optional) HTTP status code (default: 200).
100
- * @param headers - (Optional) Additional response headers.
101
- * @returns Response object with JSON data.
102
- */
103
- json(body: any, status?: number, headers?: ResponseHeaders): Response;
104
- json(body: any, headers?: ResponseHeaders): Response;
105
- json(body: any, status?: number): Response;
106
- /**
107
- * Sends a response with any content type.
108
- * Automatically determines content type if not provided.
109
- * @param body - The response body.
110
- * @param status - (Optional) HTTP status code.
111
- * @param headers - (Optional) Additional response headers.
112
- * @returns Response object.
113
- */
114
- send(body: any, status?: number, headers?: ResponseHeaders): any;
115
- send(body: any, headers?: ResponseHeaders): any;
116
- send(body: any, status?: number): any;
117
- /**
118
- * Sends an HTML response.
119
- * @param data - The HTML content as a string.
120
- * @param status - (Optional) HTTP status code (default: 200).
121
- * @param headers - (Optional) Additional response headers.
122
- * @returns Response object with HTML data.
123
- */
124
- html(data: string, status?: number, headers?: ResponseHeaders): any;
125
- html(data: string, headers?: ResponseHeaders): any;
126
- html(data: string, status?: number): any;
127
- /**
128
- * Sends a plain text response.
129
- * @param data - The text content.
130
- * @param status - (Optional) HTTP status code (default: 200).
131
- * @param headers - (Optional) Additional response headers.
132
- * @returns Response object with plain text data.
133
- */
134
- text(data: string, status?: number, headers?: ResponseHeaders): any;
135
- text(data: string, headers?: ResponseHeaders): any;
136
- text(data: string, status?: number): any;
137
- /**
138
- * Sends an XML response.
139
- * @param data - The XML content.
140
- * @param status - (Optional) HTTP status code (default: 200).
141
- * @param headers - (Optional) Additional response headers.
142
- * @returns Response object with XML data.
143
- */
144
- xml(data: string, status?: number, headers?: ResponseHeaders): any;
145
- xml(data: string, headers?: ResponseHeaders): any;
146
- xml(data: string, status?: number): any;
147
- /**
148
- * HTTP status code..
149
- * @param status - number.
150
- * @returns Response object with context all method.
151
- */
152
- status: (status: number) => this;
153
- set setStatus(status: number);
154
- get getStatus(): number;
155
- /**
156
- * Redirects to a given URL.
157
- * @param url - The target URL.
158
- * @param status - (Optional) HTTP status code (default: 302).
159
- * @returns Response object with redirect.
160
- */
161
- redirect(url: string, status?: number): Response;
162
- /**
163
- * Handles file downloads.
164
- * @param filePath - The path to the file.
165
- * @param fileName - The name of the downloaded file.
166
- * @returns Response object for file download.
167
- */
168
- download(filePath: string, fileName: string): Promise<Response>;
169
- /**
170
- * Serves a file to the client.
171
- * @param filePath - Absolute or relative path to the file.
172
- * @param fileName - (Optional) The name of the send file.
173
- * @param headers - (Optional) Additional headers.
174
- * @returns Response object with the file stream.
175
- */
176
- sendFile(filePath: string, fileName?: string, headers?: ResponseHeaders): Promise<Response>;
177
- sendFile(filePath: string, headers?: ResponseHeaders): Promise<Response>;
178
- sendFile(filePath: string, fileName?: string): Promise<Response>;
179
- /**
180
- * Getter that creates a standardized Request object from internal state
181
- * @returns {Request} - Normalized request object combining:
182
- * - Raw platform-specific request
183
- * - Parsed headers
184
- * - Route parameters
185
- *
186
- * @example
187
- * // Get standardized request
188
- * const request = ctx.req;
189
- * // Access route params
190
- * const id = request.params.get('id');
191
- */
192
- get req(): Request;
193
- protected set params(params: Record<string, any>);
194
- protected get params(): Record<string, any>;
195
- }
package/dist/context.js DELETED
@@ -1,424 +0,0 @@
1
- import { EnvironmentDetector } from "./environment";
2
- import { HeadersParser } from "./header";
3
- import { Request } from "./request";
4
- import { State } from "./utils/state";
5
- import { defaultMimeType, mimeTypes } from "./utils/staticFile";
6
- export const httpStatusMap = {
7
- 100: "Continue",
8
- 101: "Switching Protocols",
9
- 102: "Processing",
10
- 103: "Early Hints",
11
- 200: "OK",
12
- 201: "Created",
13
- 202: "Accepted",
14
- 203: "Non-Authoritative Information",
15
- 204: "No Content",
16
- 205: "Reset Content",
17
- 206: "Partial Content",
18
- 207: "Multi-Status",
19
- 208: "Already Reported",
20
- 226: "IM Used",
21
- 300: "Multiple Choices",
22
- 301: "Moved Permanently",
23
- 302: "Found",
24
- 303: "See Other",
25
- 304: "Not Modified",
26
- 305: "Use Proxy",
27
- 306: "Switch Proxy",
28
- 307: "Temporary Redirect",
29
- 308: "Permanent Redirect",
30
- 400: "Bad Request",
31
- 401: "Unauthorized",
32
- 402: "Payment Required",
33
- 403: "Forbidden",
34
- 404: "Not Found",
35
- 405: "Method Not Allowed",
36
- 406: "Not Acceptable",
37
- 407: "Proxy Authentication Required",
38
- 408: "Request Timeout",
39
- 409: "Conflict",
40
- 410: "Gone",
41
- 411: "Length Required",
42
- 412: "Precondition Failed",
43
- 413: "Payload Too Large",
44
- 414: "URI Too Long",
45
- 415: "Unsupported Media Type",
46
- 416: "Range Not Satisfiable",
47
- 417: "Expectation Failed",
48
- 418: "I'm a Teapot",
49
- 421: "Misdirected Request",
50
- 422: "Unprocessable Entity",
51
- 423: "Locked",
52
- 424: "Failed Dependency",
53
- 425: "Too Early",
54
- 426: "Upgrade Required",
55
- 428: "Precondition Required",
56
- 429: "Too Many Requests",
57
- 431: "Request Header Fields Too Large",
58
- 451: "Unavailable For Legal Reasons",
59
- 500: "Internal Server Error",
60
- 501: "Not Implemented",
61
- 502: "Bad Gateway",
62
- 503: "Service Unavailable",
63
- 504: "Gateway Timeout",
64
- 505: "HTTP Version Not Supported",
65
- 506: "Variant Also Negotiates",
66
- 507: "Insufficient Storage",
67
- 508: "Loop Detected",
68
- 510: "Not Extended",
69
- 511: "Network Authentication Required",
70
- };
71
- export class Context {
72
- #rawRequest;
73
- env = {};
74
- headers = new HeadersParser();
75
- res;
76
- pathname;
77
- url;
78
- method;
79
- #status = 200;
80
- state = new State();
81
- #params = {};
82
- #localAddress = {};
83
- #remoteAddress = {};
84
- constructor(req, connInfo) {
85
- this.#rawRequest = req;
86
- this.#remoteAddress = connInfo.remoteAddr;
87
- this.#localAddress = connInfo.localAddr;
88
- this.method = req?.method?.toUpperCase();
89
- this.pathname = this.req.urlRef.pathname;
90
- this.url = this.req.url;
91
- }
92
- header(key, value) {
93
- this.headers.set(key, value);
94
- return this;
95
- }
96
- get cookies() {
97
- const c = this.headers.getAll("cookie");
98
- let cookies = {};
99
- if (Array.isArray(c) && c.length != 0) {
100
- const cookieHeader = c.join("; ").split(";");
101
- for (const pair of cookieHeader) {
102
- const [key, value] = pair?.trim()?.split("=");
103
- cookies[key] = decodeURIComponent(value);
104
- }
105
- }
106
- else if (typeof c == "string") {
107
- const cookieHeader = c.split(";");
108
- for (const pair of cookieHeader) {
109
- const [key, value] = pair?.trim()?.split("=");
110
- cookies[key] = decodeURIComponent(value);
111
- }
112
- }
113
- return {
114
- get: (cookie) => {
115
- return cookies?.[cookie];
116
- },
117
- all: () => {
118
- return cookies;
119
- },
120
- delete: (name, options) => {
121
- const value = "";
122
- const cookieOptions = {
123
- ...options,
124
- expires: new Date(0),
125
- };
126
- const cookieHeader = `${name}=${value};${serializeOptions(cookieOptions)}`;
127
- this.headers.set("Set-Cookie", cookieHeader);
128
- },
129
- set: (name, value, options) => {
130
- const cookieHeader = `${name}=${value};${serializeOptions(options || {})}`;
131
- this.headers.set("Set-Cookie", cookieHeader);
132
- },
133
- };
134
- }
135
- json(body, ...args) {
136
- let status = this.#status;
137
- let headers = {
138
- "Content-Type": "application/json; charset=utf-8",
139
- };
140
- if (typeof args[0] === "number") {
141
- status = args[0];
142
- if (typeof args[1] === "object") {
143
- headers = { ...headers, ...args[1] };
144
- }
145
- }
146
- else if (typeof args[0] === "object") {
147
- headers = { ...headers, ...args[0] };
148
- }
149
- return this.#handleResponse(JSON.stringify(body), {
150
- status: status,
151
- headers: headers,
152
- });
153
- }
154
- send(body, ...args) {
155
- let status = this.#status;
156
- let headers = {};
157
- if (typeof args[0] === "number") {
158
- status = args[0];
159
- if (typeof args[1] === "object") {
160
- headers = args[1];
161
- }
162
- }
163
- else if (typeof args[0] === "object") {
164
- headers = args[0];
165
- }
166
- if (!headers["Content-Type"]) {
167
- if (typeof body === "string") {
168
- headers["Content-Type"] = "text/plain;";
169
- }
170
- else if (typeof body === "object" && body !== null) {
171
- headers["Content-Type"] = "application/json;";
172
- body = JSON.stringify(body);
173
- }
174
- else {
175
- headers["Content-Type"] = "application/octet-stream";
176
- }
177
- }
178
- return this.#handleResponse(body, {
179
- status: status,
180
- headers,
181
- });
182
- }
183
- html(data, ...args) {
184
- let status = this.#status;
185
- let headers = {
186
- "Content-Type": "text/html; charset=utf-8",
187
- };
188
- if (typeof args[0] === "number") {
189
- status = args[0];
190
- if (typeof args[1] === "object") {
191
- headers = { ...headers, ...args[1] };
192
- }
193
- }
194
- else if (typeof args[0] === "object") {
195
- headers = { ...headers, ...args[0] };
196
- }
197
- return this.#handleResponse(data, {
198
- status: status,
199
- headers: headers,
200
- });
201
- }
202
- text(data, ...args) {
203
- let status = this.#status;
204
- let headers = {
205
- "Content-Type": "text/plain; charset=utf-8",
206
- };
207
- if (typeof args[0] === "number") {
208
- status = args[0];
209
- if (typeof args[1] === "object") {
210
- headers = { ...headers, ...args[1] };
211
- }
212
- }
213
- else if (typeof args[0] === "object") {
214
- headers = { ...headers, ...args[0] };
215
- }
216
- return this.#handleResponse(data, {
217
- status: status,
218
- headers: headers,
219
- });
220
- }
221
- xml(data, ...args) {
222
- let status = this.#status;
223
- let headers = {
224
- "Content-Type": "application/xml; charset=utf-8",
225
- };
226
- if (typeof args[0] === "number") {
227
- status = args[0];
228
- if (typeof args[1] === "object") {
229
- headers = { ...headers, ...args[1] };
230
- }
231
- }
232
- else if (typeof args[0] === "object") {
233
- headers = { ...headers, ...args[0] };
234
- }
235
- return this.#handleResponse(data, {
236
- status: status,
237
- headers: headers,
238
- });
239
- }
240
- status = (status) => {
241
- this.#status = status;
242
- return this;
243
- };
244
- set setStatus(status) {
245
- this.#status = status;
246
- }
247
- get getStatus() {
248
- return this.#status;
249
- }
250
- redirect(url, status = 302) {
251
- return new Response(null, {
252
- status: status,
253
- headers: { Location: url },
254
- });
255
- }
256
- async download(filePath, fileName) {
257
- try {
258
- let fileExists = false;
259
- const runtime = EnvironmentDetector.getEnvironment;
260
- if (runtime === "node") {
261
- const { existsSync } = await import("fs");
262
- fileExists = existsSync(filePath);
263
- }
264
- else if (runtime === "bun") {
265
- fileExists = Bun.file(filePath).exists();
266
- }
267
- else if (runtime === "deno") {
268
- try {
269
- await Deno.stat(filePath);
270
- fileExists = true;
271
- }
272
- catch {
273
- fileExists = false;
274
- }
275
- }
276
- if (!fileExists) {
277
- throw Error("File not found");
278
- }
279
- let fileBuffer;
280
- if (runtime === "node") {
281
- const { readFileSync } = await import("fs");
282
- fileBuffer = await readFileSync(filePath);
283
- }
284
- else if (runtime === "bun") {
285
- fileBuffer = await Bun.file(filePath)
286
- .arrayBuffer()
287
- .then((buf) => new Uint8Array(buf));
288
- }
289
- else if (runtime === "deno") {
290
- fileBuffer = await Deno.readFile(filePath);
291
- }
292
- return this.#handleResponse(fileBuffer, {
293
- status: 200,
294
- headers: {
295
- "Content-Disposition": `attachment; filename="${fileName}"`,
296
- "Content-Type": "application/octet-stream",
297
- "Content-Length": fileBuffer.byteLength.toString(),
298
- },
299
- });
300
- }
301
- catch (error) {
302
- throw Error("Internal Server Error" + error?.message);
303
- }
304
- }
305
- async sendFile(filePath, ...args) {
306
- try {
307
- const runtime = EnvironmentDetector.getEnvironment;
308
- const resolvedPath = filePath;
309
- let fileExists = false;
310
- if (runtime === "node") {
311
- const { existsSync } = await import("fs");
312
- fileExists = existsSync(resolvedPath);
313
- }
314
- else if (runtime === "bun") {
315
- fileExists = Bun.file(resolvedPath).exists();
316
- }
317
- else if (runtime === "deno") {
318
- try {
319
- await Deno.stat(resolvedPath);
320
- fileExists = true;
321
- }
322
- catch {
323
- fileExists = false;
324
- }
325
- }
326
- if (!fileExists) {
327
- throw Error("File not found");
328
- }
329
- let fileSize = 0;
330
- if (runtime === "node") {
331
- const { statSync } = await import("fs");
332
- fileSize = statSync(resolvedPath).size;
333
- }
334
- else if (runtime === "bun") {
335
- fileSize = (await Bun.file(resolvedPath).arrayBuffer()).byteLength;
336
- }
337
- else if (runtime === "deno") {
338
- const fileInfo = await Deno.stat(resolvedPath);
339
- fileSize = fileInfo.size;
340
- }
341
- const ext = filePath.split(".").pop()?.toLowerCase() || "";
342
- const mimeType = mimeTypes[ext] || defaultMimeType;
343
- let fileStream;
344
- if (runtime === "node") {
345
- const { createReadStream } = await import("fs");
346
- fileStream = createReadStream(resolvedPath);
347
- }
348
- else if (runtime === "bun") {
349
- fileStream = Bun.file(resolvedPath).stream();
350
- }
351
- else if (runtime === "deno") {
352
- const file = await Deno.open(resolvedPath, { read: true });
353
- fileStream = file.readable;
354
- }
355
- let headers = {
356
- "Content-Type": mimeType,
357
- "Content-Length": fileSize.toString(),
358
- };
359
- let fileName = "";
360
- if (typeof args[0] === "string") {
361
- fileName = args[0];
362
- if (typeof args[1] === "object") {
363
- headers = { ...headers, ...args[1] };
364
- }
365
- }
366
- else if (typeof args[0] === "object") {
367
- headers = { ...headers, ...args[0] };
368
- }
369
- if (fileName) {
370
- headers["Content-Disposition"] = `attachment; filename="${fileName}"`;
371
- }
372
- return this.#handleResponse(fileStream, {
373
- status: 200,
374
- headers,
375
- });
376
- }
377
- catch (error) {
378
- throw Error("Internal Server Error" + error?.message);
379
- }
380
- }
381
- #handleResponse(body, { headers, status }) {
382
- let response = new Response(body, {
383
- status: status,
384
- headers,
385
- });
386
- let clone = response.clone();
387
- this.res = response;
388
- return clone;
389
- }
390
- get req() {
391
- return new Request(this.#rawRequest, this.params, this.#remoteAddress);
392
- }
393
- set params(params) {
394
- this.#params = params;
395
- }
396
- get params() {
397
- return this.#params;
398
- }
399
- }
400
- function serializeOptions(options) {
401
- const parts = [];
402
- if (options.maxAge) {
403
- parts.push(`Max-Age=${options.maxAge}`);
404
- }
405
- if (options.expires) {
406
- parts.push(`Expires=${options.expires.toUTCString()}`);
407
- }
408
- if (options.path) {
409
- parts.push(`Path=${options.path}`);
410
- }
411
- if (options.domain) {
412
- parts.push(`Domain=${options.domain}`);
413
- }
414
- if (options.secure) {
415
- parts.push(`Secure`);
416
- }
417
- if (options.httpOnly) {
418
- parts.push(`HttpOnly`);
419
- }
420
- if (options.sameSite) {
421
- parts.push(`SameSite=${options.sameSite}`);
422
- }
423
- return parts.join("; ");
424
- }
@@ -1,6 +0,0 @@
1
- import { HeadersParser } from "./header";
2
- export declare class EnvironmentDetector {
3
- static get getEnvironment(): "node" | "bun" | "deno" | "unknown";
4
- static detectProtocol(req: any): "unknown" | "http" | "https";
5
- static getHost(headers: HeadersParser): string;
6
- }
@@ -1,30 +0,0 @@
1
- export class EnvironmentDetector {
2
- static get getEnvironment() {
3
- if (typeof Bun !== "undefined")
4
- return "bun";
5
- if (typeof Deno !== "undefined")
6
- return "deno";
7
- if (typeof process !== "undefined" && process.versions?.node)
8
- return "node";
9
- return "unknown";
10
- }
11
- static detectProtocol(req) {
12
- try {
13
- if (this.getEnvironment === "node") {
14
- return req?.socket?.encrypted ? "https" : "http";
15
- }
16
- return "unknown";
17
- }
18
- catch (error) {
19
- throw new Error("Failed to detect protocol.");
20
- }
21
- }
22
- static getHost(headers) {
23
- try {
24
- return headers?.get("host") || "unknown";
25
- }
26
- catch (error) {
27
- throw new Error("Failed to get host.");
28
- }
29
- }
30
- }