tezx 4.0.2 → 4.0.4

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/helper/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Ctx, NetAddr } from "../types/index.js";
1
2
  import { useFormData } from "./formData.js";
2
3
  import { generateID, generateRandomBase64, generateUUID } from "./generateID.js";
3
4
  export { useFormData, generateID, generateRandomBase64, generateUUID };
@@ -8,3 +9,17 @@ declare const _default: {
8
9
  generateUUID: typeof generateUUID;
9
10
  };
10
11
  export default _default;
12
+ /**
13
+ * Retrieves remote connection details of the client from the Bun server context.
14
+ *
15
+ * This function returns network address information such as transport protocol,
16
+ * address family, IP/hostname, and port.
17
+ *
18
+ * @param {Ctx} ctx - The request context containing the Bun server and raw request.
19
+ * @returns {NetAddr} Object containing client connection details.
20
+ *
21
+ * @example
22
+ * const conn = getConnInfo(ctx);
23
+ * console.log(conn.address, conn.port);
24
+ */
25
+ export declare function getConnInfo(ctx: Ctx): NetAddr;
package/helper/index.js CHANGED
@@ -5,3 +5,6 @@ export default {
5
5
  useFormData,
6
6
  generateID, generateRandomBase64, generateUUID
7
7
  };
8
+ export function getConnInfo(ctx) {
9
+ return ctx?.server?.requestIP?.(ctx.rawRequest);
10
+ }
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Router } from "./core/router.js";
2
2
  import { TezX } from "./core/server.js";
3
3
  export { Router, TezX };
4
- export let version = "4.0.2";
4
+ export let version = "4.0.4";
5
5
  export default {
6
6
  Router,
7
7
  TezX,
@@ -1,4 +1,4 @@
1
- import { Context } from "../core/context.js";
1
+ import { Context } from "../index.js";
2
2
  import { HttpBaseResponse, Middleware } from "../types/index.js";
3
3
  /**
4
4
  * Options for Basic Authentication middleware.
@@ -1,4 +1,4 @@
1
- import { Context } from "../core/context.js";
1
+ import { Context } from "../index.js";
2
2
  import { HttpBaseResponse, Middleware } from "../types/index.js";
3
3
  /**
4
4
  * Options for Bearer Authentication middleware.
@@ -1,4 +1,4 @@
1
- import { Context } from "../core/context.js";
1
+ import { Context } from "../index.js";
2
2
  import { HttpBaseResponse, Middleware } from "../types/index.js";
3
3
  export interface CacheRule {
4
4
  /** 🎯 Condition to determine if this rule applies */
@@ -6,6 +6,7 @@ import { HttpBaseResponse } from "../types/index.js";
6
6
  export type DetectBotOptions = {
7
7
  /**
8
8
  * 🤖 List of known bot-like User-Agent patterns.
9
+ * Middleware will block requests whose User-Agent matches any of these patterns.
9
10
  * @default ["bot", "spider", "crawl", "slurp"]
10
11
  * @example
11
12
  * botUserAgents: ["bot", "crawler", "indexer"]
@@ -13,40 +14,31 @@ export type DetectBotOptions = {
13
14
  botUserAgents?: string[];
14
15
  /**
15
16
  * ⚖️ Enable rate-limiting based bot detection.
16
- * Requires `getConnInfo()` import from TezX runtime.
17
+ * Middleware will track requests per client and block if exceeding limits.
17
18
  * @default false
18
- * @example
19
- * enableRateLimiting: true
20
19
  */
21
20
  enableRateLimiting?: boolean;
22
21
  /**
23
- * 🔑 Client identifier generator function for rate limit
24
- * @default (ctx) => `${ctx.req.remoteAddress.address}:${ctx.req.remoteAddress.port}`
22
+ * 🔑 Function to generate a client identifier for rate-limiting.
23
+ * By default, it uses the client's IP and port via `getConnInfo`.
25
24
  * @example
26
- * keyGenerator: (ctx) => ctx.user?.id || ctx.ip // Use user ID if authenticated
25
+ * keyGenerator: (ctx) => ctx.user?.id || ctx.ip
27
26
  */
28
27
  keyGenerator?: (ctx: Context) => string;
29
28
  /**
30
29
  * ⚠️ Maximum allowed requests in the rate-limit window.
31
- * Only used when `enableRateLimiting` is true.
30
+ * Only used if `enableRateLimiting` is true.
32
31
  * @default 30
33
32
  */
34
33
  maxRequests?: number;
35
34
  /**
36
- * ⏱️ Time window for rate-limiting (in milliseconds).
35
+ * ⏱️ Time window for rate-limiting in milliseconds.
37
36
  * @default 60000 (1 minute)
38
37
  */
39
38
  windowMs?: number;
40
39
  /**
41
40
  * 🔄 Custom rate-limit storage implementation.
42
- * Allows integration with Redis, Memcached, or in-memory stores.
43
- * @default In-memory Map
44
- * @example
45
- * storage: {
46
- * get: (key) => myRedisClient.get(key),
47
- * set: (key, value) => myRedisClient.set(key, value),
48
- * clearExpired: () => {}
49
- * }
41
+ * Can integrate with Redis, Memcached, or an in-memory store.
50
42
  */
51
43
  storage?: {
52
44
  get: (key: string) => {
@@ -61,54 +53,44 @@ export type DetectBotOptions = {
61
53
  };
62
54
  /**
63
55
  * 🚫 Optional IP blacklist checker.
64
- * Should return true if the current request’s IP is banned or suspicious.
56
+ * Return true to block a specific IP.
65
57
  * @default () => false
66
- * @example
67
- * isBlacklisted: (ctx) => ctx.req.remoteAddress.address === "192.168.0.10"
68
58
  */
69
59
  isBlacklisted?: (ctx: Context) => boolean | Promise<boolean>;
70
60
  /**
71
61
  * 🧠 Custom bot detector function.
72
- * Use this for advanced heuristics (e.g., suspicious query params or headers).
73
- * @example
74
- * customBotDetector: (ctx) => ctx.query?.token === "weird"
62
+ * Return true to block the request based on custom logic.
75
63
  */
76
64
  customBotDetector?: (ctx: Context) => boolean | Promise<boolean>;
77
65
  /**
78
- * 🛡️ Action executed when a bot is detected.
79
- * Can return a custom HTTP response (e.g., JSON, HTML, or redirect).
66
+ * 🛡️ Callback executed when a bot is detected.
67
+ * Can return a custom HTTP response (JSON, HTML, redirect, etc.).
80
68
  * @default Responds with 403 and JSON error.
81
- * @example
82
- * onBotDetected: (ctx, reason) => ctx.status(403).json({ error: `Blocked: ${reason}` })
83
69
  */
84
70
  onBotDetected?: (ctx: Context, reason: string) => HttpBaseResponse;
85
71
  };
86
72
  /**
87
73
  * 🤖 Smart Bot Detection Middleware
88
74
  *
89
- * Detects automated or malicious requests using a combination of:
75
+ * Detects automated or malicious requests using multiple strategies:
90
76
  * - User-Agent analysis
91
- * - IP blacklisting
92
- * - Rate limiting
93
- * - Custom detection logic
94
- *
95
- * 🧩 Supports:
96
- * - Bun (uses precompiled RegExp for speed)
97
- * - Node.js / Deno (optimized `includes()` loop)
77
+ * - IP blacklist
78
+ * - Rate-limiting per client
79
+ * - Custom bot detection
98
80
  *
99
- * ⚙️ Requirements (for rate limiting):
100
- * You must import `getConnInfo` from your runtime adapter:
81
+ * The client identity for rate-limiting is determined via `getConnInfo(ctx)`,
82
+ * which returns the connection info:
101
83
  * ```ts
102
- * import { getConnInfo } from "tezx/bun";
103
- * // or
104
- * import { getConnInfo } from "tezx/node";
105
- * // or
106
- * import { getConnInfo } from "tezx/deno";
84
+ * {
85
+ * address: string; // IP address of the client
86
+ * port?: number; // Port number of the client
87
+ * transport?: string;// Transport protocol (tcp, udp)
88
+ * }
107
89
  * ```
108
90
  *
109
91
  * 📦 Example Usage:
110
92
  * ```ts
111
- * import { detectBot } from "tezx/middleware/detectBot";
93
+ * import { detectBot } from "tezx/middleware";
112
94
  *
113
95
  * app.use(detectBot({
114
96
  * enableRateLimiting: true,
@@ -1,3 +1,4 @@
1
+ import { getConnInfo } from "../helper/index.js";
1
2
  import { createRateLimitDefaultStorage, isRateLimit } from "../utils/rateLimit.js";
2
3
  export const detectBot = (opts = {}) => {
3
4
  const botUAs = opts.botUserAgents || ["bot", "spider", "crawl", "slurp"];
@@ -5,7 +6,7 @@ export const detectBot = (opts = {}) => {
5
6
  const botRegex = new RegExp(botUAs.join("|"), "i");
6
7
  checkBot = (ua) => botRegex.test(ua);
7
8
  const keyGenerator = opts.keyGenerator ?? ((ctx) => {
8
- const addr = ctx.req.remoteAddress;
9
+ const addr = getConnInfo(ctx);
9
10
  return addr ? `${addr.address}:${addr.port}` : "unknown";
10
11
  });
11
12
  const maxReq = opts.maxRequests || 30;
@@ -4,7 +4,6 @@ export * from "./cache-control.js";
4
4
  export * from "./cors.js";
5
5
  export * from "./detect-bot.js";
6
6
  export * from "./etag.js";
7
- export * from "./getConnInfo.js";
8
7
  export * from "./i18n.js";
9
8
  export * from "./logger.js";
10
9
  export * from "./pagination.js";
@@ -4,7 +4,6 @@ export * from "./cache-control.js";
4
4
  export * from "./cors.js";
5
5
  export * from "./detect-bot.js";
6
6
  export * from "./etag.js";
7
- export * from "./getConnInfo.js";
8
7
  export * from "./i18n.js";
9
8
  export * from "./logger.js";
10
9
  export * from "./pagination.js";
@@ -39,8 +39,9 @@ const paginationHandler = (options = {}) => {
39
39
  pagination,
40
40
  };
41
41
  ctx.body = body;
42
- if (next) {
43
- return await next();
42
+ let res = await next();
43
+ if (res) {
44
+ return res;
44
45
  }
45
46
  return ctx.json(body);
46
47
  }
@@ -1,4 +1,4 @@
1
- import { Context } from "../core/context.js";
1
+ import { Context } from "../index.js";
2
2
  import { HttpBaseResponse, Middleware } from "../types/index.js";
3
3
  export type RateLimiterOptions = {
4
4
  /**
@@ -14,15 +14,16 @@ export type RateLimiterOptions = {
14
14
  */
15
15
  windowMs: number;
16
16
  /**
17
- * 🔑 Client identifier generator function
18
- * @default (ctx) => `${ctx.req.remoteAddress.address}:${ctx.req.remoteAddress.port}`
17
+ * 🔑 Function to generate a client identifier for rate-limiting.
18
+ * By default, it uses `X-Forwarded-For`, `Client-IP`, or `getConnInfo(ctx)`.
19
19
  * @example
20
- * keyGenerator: (ctx) => ctx.user?.id || ctx.ip // Use user ID if authenticated
20
+ * keyGenerator: (ctx) => ctx.user?.id || ctx.ip
21
21
  */
22
22
  keyGenerator?: (ctx: Context) => string;
23
23
  /**
24
- * 🔄 Custom cache storage implementation (e.g., using `Map`, `Redis`, etc.).
25
- * By default, it uses a `Map<string, { count: number; resetTime: number }>`.
24
+ * 🔄 Custom cache/storage implementation.
25
+ * Must provide `get`, `set`, and `clearExpired` methods.
26
+ * @default In-memory Map via `createRateLimitDefaultStorage()`
26
27
  */
27
28
  storage?: {
28
29
  get: (key: string) => {
@@ -36,42 +37,39 @@ export type RateLimiterOptions = {
36
37
  clearExpired: () => void;
37
38
  };
38
39
  /**
39
- * 🛑 Custom rate limit exceeded handler
40
- * @default Sends 429 status with Retry-After header
41
- * @example
42
- * onError: (ctx, retryAfter) => {
43
- * ctx.status = 429;
44
- * throw new Error( `Rate limit exceeded. Try again in ${retryAfter} seconds.`);
45
- * }
40
+ * 🛑 Custom handler when rate limit is exceeded.
41
+ * @default Throws 429 status with Retry-After header
46
42
  */
47
43
  onError?: (ctx: Context, retryAfter: number, error: Error) => HttpBaseResponse;
48
44
  };
49
45
  /**
50
- * 🚦 Rate limiting middleware for request throttling
46
+ * 🚦 Rate Limiter Middleware
47
+ *
48
+ * Throttles requests per client based on a sliding window.
49
+ * Supports custom client identification and storage backends.
50
+ *
51
+ * Client IP detection uses (in order):
52
+ * 1. `X-Forwarded-For` header
53
+ * 2. `Client-IP` header
54
+ * 3. `getConnInfo(ctx)` fallback
51
55
  *
52
- * Enforces maximum request limits per client with sliding window.
53
- * Currently supports in-memory storage only (Redis coming soon).
54
- * @requires
55
- * *
56
- ```ts
57
- import { getConnInfo } from "tezx/middleware";
58
- ```
59
- * @param {RateLimiterOptions} options - Configuration
60
- * @returns {Middleware} Middleware function
56
+ * ```ts
57
+ * import { getConnInfo } from "tezx/helper";
58
+ * ```
59
+ *
60
+ * @param options RateLimiterOptions
61
+ * @returns Middleware function
61
62
  *
62
63
  * @example
63
64
  * // Basic rate limiting (100 requests/minute)
64
- * app.use(rateLimiter({
65
- * maxRequests: 100,
66
- * windowMs: 60_000
67
- * }));
65
+ * app.use(rateLimiter({ maxRequests: 100, windowMs: 60_000 }));
68
66
  *
69
67
  * // Custom client identification
70
68
  * app.use(rateLimiter({
71
69
  * maxRequests: 10,
72
70
  * windowMs: 10_000,
73
- * keyGenerator: (ctx) => ctx.user?.id || ctx.remoteAddress.address
71
+ * keyGenerator: (ctx) => ctx.user?.id
74
72
  * }));
75
73
  */
76
74
  declare const rateLimiter: <T extends Record<string, any> = {}, Path extends string = any>(options: RateLimiterOptions) => Middleware<T, Path>;
77
- export { rateLimiter, rateLimiter as default };
75
+ export { rateLimiter as default, rateLimiter };
@@ -1,3 +1,4 @@
1
+ import { getConnInfo } from "../helper/index.js";
1
2
  import { createRateLimitDefaultStorage, isRateLimit } from "../utils/rateLimit.js";
2
3
  const rateLimiter = (options) => {
3
4
  const { maxRequests, windowMs, keyGenerator = (ctx) => {
@@ -9,9 +10,8 @@ const rateLimiter = (options) => {
9
10
  const clientIp = ctx.req.header("client-ip");
10
11
  if (clientIp)
11
12
  return clientIp;
12
- const addr = ctx.req.remoteAddress?.address || "unknown";
13
- const port = ctx.req.remoteAddress?.port || "0";
14
- return `${addr}:${port}`;
13
+ const { port, address } = getConnInfo(ctx) ?? {};
14
+ return `${address}:${port}`;
15
15
  }, storage = createRateLimitDefaultStorage(), onError = (ctx, retryAfter, error) => {
16
16
  ctx.status(429);
17
17
  throw new Error(`Rate limit exceeded. Try again in ${retryAfter} seconds.`);
@@ -30,4 +30,4 @@ const rateLimiter = (options) => {
30
30
  return await next();
31
31
  };
32
32
  };
33
- export { rateLimiter, rateLimiter as default };
33
+ export { rateLimiter as default, rateLimiter };
@@ -1,4 +1,4 @@
1
- import { Context } from "../core/context.js";
1
+ import { Context } from "../index.js";
2
2
  import { Middleware } from "../types/index.js";
3
3
  export type XSSProtectionOptions = {
4
4
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tezx",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
4
4
  "description": "TezX is a modern, ultra-lightweight, and high-performance JavaScript framework built specifically for Bun. It provides a minimal yet powerful API, seamless environment management, and a high-concurrency HTTP engine for building fast, scalable web applications.",
5
5
  "type": "module",
6
6
  "main": "cjs/index.js",
package/types/index.d.ts CHANGED
@@ -115,7 +115,7 @@ export interface CookieOptions {
115
115
  /** Controls cross-site request behavior. One of "Strict", "Lax", or "None". */
116
116
  sameSite?: "Strict" | "Lax" | "None";
117
117
  }
118
- import { Context } from "../core/context.js";
118
+ import { BaseContext, Context } from "../index.js";
119
119
  import { RequestHeader, ResponseHeader } from "./headers.js";
120
120
  /**
121
121
  * Options to customize static file serving behavior.
@@ -236,7 +236,7 @@ export type HttpBaseResponse = Response | Promise<Response>;
236
236
  * @template T - Custom environment or app-level data.
237
237
  * @template Path - Type of the route path (optional).
238
238
  */
239
- export type Ctx<T extends Record<string, any> = {}, Path extends string = any> = Context<Path> & T & {
239
+ export type Ctx<T extends Record<string, any> = {}, Path extends string = any> = BaseContext<Path> & T & {
240
240
  [key: string]: any;
241
241
  /**
242
242
  * Response body, can be string, Buffer, stream, etc. like context propagation.
@@ -311,7 +311,11 @@ export interface FormDataOptions {
311
311
  */
312
312
  type TransportType = "tcp" | "udp" | "unix" | "pipe" | "unixpacket";
313
313
  /**
314
- * A normalized network address description.
314
+ * Remote address details of the connected client.
315
+ * @property {string} [transport] - Transport protocol (e.g., "tcp", "udp").
316
+ * @property {"IPv4" | "IPv6" | "Unix"} [family] - Address family.
317
+ * @property {string} [hostname] - Hostname or IP address.
318
+ * @property {number} [port] - Port number.
315
319
  */
316
320
  export type NetAddr = {
317
321
  /** Transport protocol used by the connection. */
@@ -1,4 +1,117 @@
1
1
  export declare const mimeTypes: {
2
- [key: string]: string;
2
+ readonly html: "text/html";
3
+ readonly htm: "text/html";
4
+ readonly css: "text/css";
5
+ readonly js: "text/javascript";
6
+ readonly mjs: "text/javascript";
7
+ readonly json: "application/json";
8
+ readonly xml: "application/xml";
9
+ readonly txt: "text/plain";
10
+ readonly md: "text/markdown";
11
+ readonly csv: "text/csv";
12
+ readonly tsv: "text/tab-separated-values";
13
+ readonly rtf: "application/rtf";
14
+ readonly markdown: "text/markdown";
15
+ readonly jsx: "text/javascript";
16
+ readonly ts: "text/typescript";
17
+ readonly tsx: "text/typescript";
18
+ readonly jsonld: "application/ld+json";
19
+ readonly png: "image/png";
20
+ readonly jpg: "image/jpeg";
21
+ readonly jpeg: "image/jpeg";
22
+ readonly gif: "image/gif";
23
+ readonly svg: "image/svg+xml";
24
+ readonly webp: "image/webp";
25
+ readonly ico: "image/x-icon";
26
+ readonly bmp: "image/bmp";
27
+ readonly tiff: "image/tiff";
28
+ readonly psd: "image/vnd.adobe.photoshop";
29
+ readonly tif: "image/tiff";
30
+ readonly avif: "image/avif";
31
+ readonly woff: "font/woff";
32
+ readonly woff2: "font/woff2";
33
+ readonly ttf: "font/ttf";
34
+ readonly otf: "font/otf";
35
+ readonly eot: "application/vnd.ms-fontobject";
36
+ readonly mp4: "video/mp4";
37
+ readonly webm: "video/webm";
38
+ readonly ogg: "video/ogg";
39
+ readonly mov: "video/quicktime";
40
+ readonly avi: "video/x-msvideo";
41
+ readonly wmv: "video/x-ms-wmv";
42
+ readonly flv: "video/x-flv";
43
+ readonly "3gp": "video/3gpp";
44
+ readonly mkv: "video/x-matroska";
45
+ readonly mpeg: "video/mpeg";
46
+ readonly mpg: "video/mpeg";
47
+ readonly mp3: "audio/mpeg";
48
+ readonly wav: "audio/wav";
49
+ readonly aac: "audio/aac";
50
+ readonly flac: "audio/flac";
51
+ readonly m4a: "audio/mp4";
52
+ readonly mid: "audio/midi";
53
+ readonly midi: "audio/midi";
54
+ readonly weba: "audio/webm";
55
+ readonly pdf: "application/pdf";
56
+ readonly odp: "application/vnd.oasis.opendocument.presentation";
57
+ readonly zip: "application/zip";
58
+ readonly gz: "application/gzip";
59
+ readonly tar: "application/x-tar";
60
+ readonly rar: "application/x-rar-compressed";
61
+ readonly _7z: "application/x-7z-compressed";
62
+ readonly bz2: "application/x-bzip2";
63
+ readonly "7z": "application/x-7z-compressed";
64
+ readonly doc: "application/msword";
65
+ readonly docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
66
+ readonly xls: "application/vnd.ms-excel";
67
+ readonly xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
68
+ readonly ppt: "application/vnd.ms-powerpoint";
69
+ readonly pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation";
70
+ readonly odt: "application/vnd.oasis.opendocument.text";
71
+ readonly ods: "application/vnd.oasis.opendocument.spreadsheet";
72
+ readonly wasm: "application/wasm";
73
+ readonly map: "application/json";
74
+ readonly yaml: "application/yaml";
75
+ readonly yml: "application/yaml";
76
+ readonly proto: "text/plain";
77
+ readonly graphql: "application/graphql";
78
+ readonly pem: "application/x-pem-file";
79
+ readonly cer: "application/pkix-cert";
80
+ readonly crt: "application/x-x509-ca-cert";
81
+ readonly key: "application/x-pem-file";
82
+ readonly pfx: "application/x-pkcs12";
83
+ readonly glb: "model/gltf-binary";
84
+ readonly gltf: "model/gltf+json";
85
+ readonly obj: "model/obj";
86
+ readonly stl: "model/stl";
87
+ readonly usdz: "model/vnd.usdz+zip";
88
+ readonly exe: "application/x-msdownload";
89
+ readonly dmg: "application/x-apple-diskimage";
90
+ readonly deb: "application/x-debian-package";
91
+ readonly rpm: "application/x-redhat-package-manager";
92
+ readonly apk: "application/vnd.android.package-archive";
93
+ readonly bin: "application/octet-stream";
94
+ readonly iso: "application/octet-stream";
95
+ readonly webmanifest: "application/manifest+json";
96
+ readonly ics: "text/calendar";
97
+ readonly vcf: "text/vcard";
98
+ readonly warc: "application/warc";
99
+ readonly atom: "application/atom+xml";
100
+ readonly rss: "application/rss+xml";
101
+ readonly dll: "application/x-msdownload";
102
+ readonly sh: "application/x-sh";
103
+ readonly py: "text/x-python";
104
+ readonly rb: "text/x-ruby";
105
+ readonly pl: "text/x-perl";
106
+ readonly php: "application/x-httpd-php";
107
+ readonly torrent: "application/x-bittorrent";
108
+ readonly ipa: "application/vnd.iphone";
109
+ readonly eps: "application/postscript";
110
+ readonly ps: "application/postscript";
111
+ readonly ai: "application/postscript";
112
+ readonly swf: "application/x-shockwave-flash";
113
+ readonly jar: "application/java-archive";
114
+ readonly gcode: "text/x.gcode";
3
115
  };
116
+ export type ContentType = (typeof mimeTypes[keyof typeof mimeTypes]) | "application/octet-stream" | (string & {});
4
117
  export declare const defaultMimeType = "application/octet-stream";
@@ -12,6 +12,10 @@ export const mimeTypes = {
12
12
  tsv: "text/tab-separated-values",
13
13
  rtf: "application/rtf",
14
14
  markdown: "text/markdown",
15
+ jsx: "text/javascript",
16
+ ts: "text/typescript",
17
+ tsx: "text/typescript",
18
+ jsonld: "application/ld+json",
15
19
  png: "image/png",
16
20
  jpg: "image/jpeg",
17
21
  jpeg: "image/jpeg",
@@ -22,6 +26,13 @@ export const mimeTypes = {
22
26
  bmp: "image/bmp",
23
27
  tiff: "image/tiff",
24
28
  psd: "image/vnd.adobe.photoshop",
29
+ tif: "image/tiff",
30
+ avif: "image/avif",
31
+ woff: "font/woff",
32
+ woff2: "font/woff2",
33
+ ttf: "font/ttf",
34
+ otf: "font/otf",
35
+ eot: "application/vnd.ms-fontobject",
25
36
  mp4: "video/mp4",
26
37
  webm: "video/webm",
27
38
  ogg: "video/ogg",
@@ -30,6 +41,9 @@ export const mimeTypes = {
30
41
  wmv: "video/x-ms-wmv",
31
42
  flv: "video/x-flv",
32
43
  "3gp": "video/3gpp",
44
+ mkv: "video/x-matroska",
45
+ mpeg: "video/mpeg",
46
+ mpg: "video/mpeg",
33
47
  mp3: "audio/mpeg",
34
48
  wav: "audio/wav",
35
49
  aac: "audio/aac",
@@ -37,11 +51,7 @@ export const mimeTypes = {
37
51
  m4a: "audio/mp4",
38
52
  mid: "audio/midi",
39
53
  midi: "audio/midi",
40
- woff: "font/woff",
41
- woff2: "font/woff2",
42
- ttf: "font/ttf",
43
- otf: "font/otf",
44
- eot: "application/vnd.ms-fontobject",
54
+ weba: "audio/webm",
45
55
  pdf: "application/pdf",
46
56
  odp: "application/vnd.oasis.opendocument.presentation",
47
57
  zip: "application/zip",
@@ -80,6 +90,8 @@ export const mimeTypes = {
80
90
  deb: "application/x-debian-package",
81
91
  rpm: "application/x-redhat-package-manager",
82
92
  apk: "application/vnd.android.package-archive",
93
+ bin: "application/octet-stream",
94
+ iso: "application/octet-stream",
83
95
  webmanifest: "application/manifest+json",
84
96
  ics: "text/calendar",
85
97
  vcf: "text/vcard",
@@ -1,4 +1,4 @@
1
- import { Context } from "../core/context.js";
1
+ import { Context } from "../index.js";
2
2
  import { HttpBaseResponse, ResponseHeaders } from "../types/index.js";
3
3
  export declare let notFoundResponse: (ctx: Context) => HttpBaseResponse;
4
4
  export declare function mergeHeaders(existing?: Headers, init?: ResponseHeaders): Headers;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getConnInfo = getConnInfo;
4
- function getConnInfo() {
5
- return (ctx, next) => {
6
- let server = ctx.server;
7
- if (server && server.requestIP) {
8
- ctx.req.remoteAddress = server.requestIP(ctx.rawRequest);
9
- }
10
- return next();
11
- };
12
- }
13
- exports.default = getConnInfo;
@@ -1,22 +0,0 @@
1
- import { Middleware } from "../types/index.js";
2
- /**
3
- * Middleware to extract and inject connection information into the request context.
4
- *
5
- * This middleware reads the socket's remote address information (like IP, port, and family)
6
- * from the request object and attaches it to `ctx.req.remoteAddress`.
7
- *
8
- * @returns {Middleware<any>} The middleware function that sets `ctx.req.remoteAddress`.
9
- *
10
- * @example
11
- * import { getConnInfo } from "tezx/middleware";
12
- *
13
- * app.use(getConnInfo());
14
- *
15
- * // Access later in route handler:
16
- * router.get("/", (ctx) => {
17
- * const ip = ctx.req.remoteAddress?.address;
18
- * return new Response(`Your IP: ${ip}`);
19
- * });
20
- */
21
- export declare function getConnInfo<T extends Record<string, any> = {}, Path extends string = any>(): Middleware<T, Path>;
22
- export default getConnInfo;
@@ -1,10 +0,0 @@
1
- export function getConnInfo() {
2
- return (ctx, next) => {
3
- let server = ctx.server;
4
- if (server && server.requestIP) {
5
- ctx.req.remoteAddress = server.requestIP(ctx.rawRequest);
6
- }
7
- return next();
8
- };
9
- }
10
- export default getConnInfo;