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/cjs/core/context.js +16 -52
- package/cjs/core/request.js +0 -1
- package/cjs/core/server.js +26 -21
- package/cjs/helper/index.js +4 -0
- package/cjs/index.js +1 -1
- package/cjs/middleware/detect-bot.js +2 -1
- package/cjs/middleware/index.js +0 -1
- package/cjs/middleware/pagination.js +3 -2
- package/cjs/middleware/rate-limiter.js +5 -5
- package/cjs/utils/mimeTypes.js +17 -5
- package/cookie/index.d.ts +1 -1
- package/core/context.d.ts +30 -32
- package/core/context.js +16 -52
- package/core/request.d.ts +1 -13
- package/core/request.js +0 -1
- package/core/server.d.ts +1 -1
- package/core/server.js +26 -21
- package/helper/index.d.ts +15 -0
- package/helper/index.js +3 -0
- package/index.js +1 -1
- package/middleware/basic-auth.d.ts +1 -1
- package/middleware/bearer-auth.d.ts +1 -1
- package/middleware/cache-control.d.ts +1 -1
- package/middleware/detect-bot.d.ts +24 -42
- package/middleware/detect-bot.js +2 -1
- package/middleware/index.d.ts +0 -1
- package/middleware/index.js +0 -1
- package/middleware/pagination.js +3 -2
- package/middleware/rate-limiter.d.ts +27 -29
- package/middleware/rate-limiter.js +4 -4
- package/middleware/xss-protection.d.ts +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +7 -3
- package/utils/mimeTypes.d.ts +114 -1
- package/utils/mimeTypes.js +17 -5
- package/utils/response.d.ts +1 -1
- package/cjs/middleware/getConnInfo.js +0 -13
- package/middleware/getConnInfo.d.ts +0 -22
- package/middleware/getConnInfo.js +0 -10
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
package/index.js
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
* 🔑
|
|
24
|
-
*
|
|
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
|
|
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
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
* 🛡️
|
|
79
|
-
* Can return a custom HTTP response (
|
|
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
|
|
75
|
+
* Detects automated or malicious requests using multiple strategies:
|
|
90
76
|
* - User-Agent analysis
|
|
91
|
-
* - IP
|
|
92
|
-
* - Rate
|
|
93
|
-
* - Custom detection
|
|
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
|
-
*
|
|
100
|
-
*
|
|
81
|
+
* The client identity for rate-limiting is determined via `getConnInfo(ctx)`,
|
|
82
|
+
* which returns the connection info:
|
|
101
83
|
* ```ts
|
|
102
|
-
*
|
|
103
|
-
* //
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
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
|
|
93
|
+
* import { detectBot } from "tezx/middleware";
|
|
112
94
|
*
|
|
113
95
|
* app.use(detectBot({
|
|
114
96
|
* enableRateLimiting: true,
|
package/middleware/detect-bot.js
CHANGED
|
@@ -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
|
|
9
|
+
const addr = getConnInfo(ctx);
|
|
9
10
|
return addr ? `${addr.address}:${addr.port}` : "unknown";
|
|
10
11
|
});
|
|
11
12
|
const maxReq = opts.maxRequests || 30;
|
package/middleware/index.d.ts
CHANGED
package/middleware/index.js
CHANGED
package/middleware/pagination.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Context } from "../
|
|
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
|
-
* 🔑
|
|
18
|
-
*
|
|
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
|
|
20
|
+
* keyGenerator: (ctx) => ctx.user?.id || ctx.ip
|
|
21
21
|
*/
|
|
22
22
|
keyGenerator?: (ctx: Context) => string;
|
|
23
23
|
/**
|
|
24
|
-
* 🔄 Custom cache
|
|
25
|
-
*
|
|
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
|
|
40
|
-
* @default
|
|
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
|
|
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
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
|
|
57
|
-
|
|
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
|
|
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
|
|
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
|
|
13
|
-
|
|
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
|
|
33
|
+
export { rateLimiter as default, rateLimiter };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tezx",
|
|
3
|
-
"version": "4.0.
|
|
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 "../
|
|
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> =
|
|
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
|
-
*
|
|
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. */
|
package/utils/mimeTypes.d.ts
CHANGED
|
@@ -1,4 +1,117 @@
|
|
|
1
1
|
export declare const mimeTypes: {
|
|
2
|
-
|
|
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";
|
package/utils/mimeTypes.js
CHANGED
|
@@ -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
|
-
|
|
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",
|
package/utils/response.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Context } from "../
|
|
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;
|