tezx 2.0.8 → 2.0.11
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/router.js +2 -2
- package/cjs/helper/common.js +7 -1
- package/cjs/helper/index.js +8 -9
- package/cjs/index.js +7 -8
- package/cjs/types/index.js +2 -0
- package/cjs/utils/debugging.js +0 -1
- package/cjs/utils/regexRouter.js +1 -1
- package/cjs/ws/node.js +1 -1
- package/core/MiddlewareConfigure.d.ts +1 -3
- package/core/common.d.ts +1 -1
- package/core/config.d.ts +1 -2
- package/core/context.d.ts +4 -13
- package/core/request.d.ts +3 -21
- package/core/router.d.ts +43 -54
- package/core/router.js +2 -2
- package/core/server.d.ts +2 -2
- package/helper/common.js +7 -1
- package/helper/index.d.ts +8 -8
- package/helper/index.js +3 -4
- package/index.d.ts +5 -8
- package/index.js +5 -6
- package/middleware/basicAuth.d.ts +1 -1
- package/middleware/cacheControl.d.ts +2 -1
- package/middleware/cors.d.ts +1 -1
- package/middleware/detectBot.d.ts +1 -1
- package/middleware/index.d.ts +1 -1
- package/middleware/logger.d.ts +1 -1
- package/middleware/pagination.d.ts +1 -2
- package/middleware/powered-by.d.ts +1 -1
- package/middleware/rateLimiter.d.ts +1 -1
- package/middleware/request-id.d.ts +1 -1
- package/middleware/requestTimeout.d.ts +1 -1
- package/middleware/sanitizeHeader.d.ts +1 -1
- package/middleware/secureHeaders.d.ts +1 -1
- package/middleware/xssProtection.d.ts +1 -1
- package/package.json +4 -3
- package/types/index.d.ts +59 -0
- package/types/index.js +1 -0
- package/utils/debugging.d.ts +0 -5
- package/utils/debugging.js +0 -1
- package/utils/regexRouter.d.ts +1 -1
- package/utils/regexRouter.js +1 -1
- package/utils/staticFile.d.ts +2 -1
- package/ws/index.d.ts +1 -1
- package/ws/node.js +1 -1
package/cjs/core/router.js
CHANGED
|
@@ -250,7 +250,7 @@ class Router extends MiddlewareConfigure_js_1.default {
|
|
|
250
250
|
if (!config_js_1.GlobalConfig.overwriteMethod && handler.has(method))
|
|
251
251
|
return;
|
|
252
252
|
return handler.set(method, {
|
|
253
|
-
callback,
|
|
253
|
+
callback: callback,
|
|
254
254
|
paramNames: [],
|
|
255
255
|
regex: regex,
|
|
256
256
|
middlewares: finalMiddleware
|
|
@@ -275,7 +275,7 @@ class Router extends MiddlewareConfigure_js_1.default {
|
|
|
275
275
|
if (!config_js_1.GlobalConfig.overwriteMethod && handler.has(method))
|
|
276
276
|
return;
|
|
277
277
|
return handler.set(method, {
|
|
278
|
-
callback,
|
|
278
|
+
callback: callback,
|
|
279
279
|
regex: regex,
|
|
280
280
|
paramNames: paramNames,
|
|
281
281
|
middlewares: finalMiddleware
|
package/cjs/helper/common.js
CHANGED
|
@@ -6,6 +6,12 @@ function generateID() {
|
|
|
6
6
|
const random = Math.floor(Math.random() * 0xffffffffffff)
|
|
7
7
|
.toString(16)
|
|
8
8
|
.padStart(12, "0");
|
|
9
|
-
|
|
9
|
+
let pid = Math.floor(Math.random() * 0xffff).toString(16).padStart(4, "0");
|
|
10
|
+
if (typeof Deno !== "undefined" && typeof Deno.pid === "number") {
|
|
11
|
+
pid = (Deno.pid % 0xffff).toString(16).padStart(4, "0");
|
|
12
|
+
}
|
|
13
|
+
else if (typeof process !== "undefined" && typeof process.pid === "number") {
|
|
14
|
+
pid = (process.pid % 0xffff).toString(16).padStart(4, "0");
|
|
15
|
+
}
|
|
10
16
|
return `${timestamp}-${random}-${pid}`;
|
|
11
17
|
}
|
package/cjs/helper/index.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.sanitizePathSplit = exports.GlobalConfig = exports.generateID = exports.Environment = exports.colorText = void 0;
|
|
4
4
|
const config_js_1 = require("../core/config.js");
|
|
5
|
+
Object.defineProperty(exports, "GlobalConfig", { enumerable: true, get: function () { return config_js_1.GlobalConfig; } });
|
|
5
6
|
const environment_js_1 = require("../core/environment.js");
|
|
7
|
+
Object.defineProperty(exports, "Environment", { enumerable: true, get: function () { return environment_js_1.Environment; } });
|
|
8
|
+
const colors_js_1 = require("../utils/colors.js");
|
|
9
|
+
Object.defineProperty(exports, "colorText", { enumerable: true, get: function () { return colors_js_1.colorText; } });
|
|
6
10
|
const url_js_1 = require("../utils/url.js");
|
|
11
|
+
Object.defineProperty(exports, "sanitizePathSplit", { enumerable: true, get: function () { return url_js_1.sanitizePathSplit; } });
|
|
7
12
|
const common_js_1 = require("./common.js");
|
|
8
|
-
|
|
9
|
-
Object.defineProperty(exports, "GlobalConfig", { enumerable: true, get: function () { return config_js_2.GlobalConfig; } });
|
|
10
|
-
var environment_js_2 = require("../core/environment.js");
|
|
11
|
-
Object.defineProperty(exports, "Environment", { enumerable: true, get: function () { return environment_js_2.Environment; } });
|
|
12
|
-
var url_js_2 = require("../utils/url.js");
|
|
13
|
-
Object.defineProperty(exports, "sanitizePathSplit", { enumerable: true, get: function () { return url_js_2.sanitizePathSplit; } });
|
|
14
|
-
var common_js_2 = require("./common.js");
|
|
15
|
-
Object.defineProperty(exports, "generateID", { enumerable: true, get: function () { return common_js_2.generateID; } });
|
|
13
|
+
Object.defineProperty(exports, "generateID", { enumerable: true, get: function () { return common_js_1.generateID; } });
|
|
16
14
|
exports.default = {
|
|
17
15
|
Environment: environment_js_1.Environment,
|
|
16
|
+
colorText: colors_js_1.colorText,
|
|
18
17
|
GlobalConfig: config_js_1.GlobalConfig,
|
|
19
18
|
sanitizePathSplit: url_js_1.sanitizePathSplit,
|
|
20
19
|
generateID: common_js_1.generateID,
|
package/cjs/index.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.version = exports.
|
|
3
|
+
exports.version = exports.TezX = exports.Router = exports.regexMatchRoute = exports.compileRegexRoute = void 0;
|
|
4
4
|
const router_js_1 = require("./core/router.js");
|
|
5
|
+
Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return router_js_1.Router; } });
|
|
5
6
|
const server_js_1 = require("./core/server.js");
|
|
7
|
+
Object.defineProperty(exports, "TezX", { enumerable: true, get: function () { return server_js_1.TezX; } });
|
|
6
8
|
const regexRouter_js_1 = require("./utils/regexRouter.js");
|
|
7
|
-
Object.defineProperty(exports, "regexMatchRoute", { enumerable: true, get: function () { return regexRouter_js_1.regexMatchRoute; } });
|
|
8
9
|
Object.defineProperty(exports, "compileRegexRoute", { enumerable: true, get: function () { return regexRouter_js_1.compileRegexRoute; } });
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var server_js_2 = require("./core/server.js");
|
|
12
|
-
Object.defineProperty(exports, "TezX", { enumerable: true, get: function () { return server_js_2.TezX; } });
|
|
13
|
-
exports.version = "2.0.8";
|
|
10
|
+
Object.defineProperty(exports, "regexMatchRoute", { enumerable: true, get: function () { return regexRouter_js_1.regexMatchRoute; } });
|
|
11
|
+
exports.version = "2.0.11";
|
|
14
12
|
exports.default = {
|
|
15
13
|
Router: router_js_1.Router,
|
|
16
|
-
regexMatchRoute: regexRouter_js_1.regexMatchRoute,
|
|
14
|
+
regexMatchRoute: regexRouter_js_1.regexMatchRoute,
|
|
15
|
+
compileRegexRoute: regexRouter_js_1.compileRegexRoute,
|
|
17
16
|
TezX: server_js_1.TezX,
|
|
18
17
|
version: exports.version,
|
|
19
18
|
};
|
package/cjs/utils/debugging.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.loggerOutput = void 0;
|
|
4
4
|
const colors_js_1 = require("./colors.js");
|
|
5
5
|
const loggerOutput = (level, message, ...args) => {
|
|
6
|
-
const timestamp = new Date().toISOString();
|
|
7
6
|
const LEVEL_COLORS = {
|
|
8
7
|
info: colors_js_1.COLORS.blue,
|
|
9
8
|
warn: colors_js_1.COLORS.yellow,
|
package/cjs/utils/regexRouter.js
CHANGED
|
@@ -46,7 +46,7 @@ function addBaseToRegex(basePath, routeRegex) {
|
|
|
46
46
|
const finalRegex = new RegExp(`^${combined}$`);
|
|
47
47
|
return finalRegex;
|
|
48
48
|
}
|
|
49
|
-
function regexMatchRoute(regex, url, paramNames) {
|
|
49
|
+
function regexMatchRoute(regex, url, paramNames = []) {
|
|
50
50
|
const match = url.match(regex);
|
|
51
51
|
if (!match)
|
|
52
52
|
return { success: false, params: {} };
|
package/cjs/ws/node.js
CHANGED
|
@@ -44,7 +44,7 @@ class NodeTransport {
|
|
|
44
44
|
maxPayload: options.maxPayload ?? 1048576,
|
|
45
45
|
perMessageDeflate: options.perMessageDeflate ?? false,
|
|
46
46
|
});
|
|
47
|
-
server
|
|
47
|
+
server?.on("upgrade", (request, socket, head) => {
|
|
48
48
|
this.wss?.handleUpgrade(request, socket, head, (ws) => {
|
|
49
49
|
this.wss?.emit("connection", ws, request);
|
|
50
50
|
this.setupHandlers(ws, event, options);
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
+
import { DuplicateMiddlewares, Middleware, UniqueMiddlewares } from "../types/index.js";
|
|
1
2
|
import { CommonHandler } from "./common.js";
|
|
2
|
-
import { Middleware } from "./router.js";
|
|
3
|
-
export type DuplicateMiddlewares = Middleware<any>[];
|
|
4
|
-
export type UniqueMiddlewares = Set<Middleware<any>>;
|
|
5
3
|
export declare class TriMiddleware {
|
|
6
4
|
children: Map<string, TriMiddleware>;
|
|
7
5
|
middlewares: DuplicateMiddlewares | UniqueMiddlewares;
|
package/core/common.d.ts
CHANGED
package/core/config.d.ts
CHANGED
package/core/context.d.ts
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
|
+
import { CookieOptions, HTTPMethod, PathType, ResponseHeaders } from "../types/index.js";
|
|
1
2
|
import { State } from "../utils/state.js";
|
|
2
|
-
import {
|
|
3
|
+
import { Request as RequestParser } from "./request.js";
|
|
3
4
|
import { TezXServeOptions } from "./server.js";
|
|
4
|
-
export
|
|
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 type ResponseHeaders = Record<string, string>;
|
|
14
|
-
export declare class Context<T extends Record<string, any> = {}> {
|
|
5
|
+
export declare class Context<T extends Record<string, any> = {}, Path extends PathType = any> {
|
|
15
6
|
#private;
|
|
16
7
|
[key: string]: any;
|
|
17
8
|
rawRequest: Request;
|
|
@@ -192,7 +183,7 @@ export declare class Context<T extends Record<string, any> = {}> {
|
|
|
192
183
|
* // Access route params
|
|
193
184
|
* const id = request.params.get('id');
|
|
194
185
|
*/
|
|
195
|
-
get req(): RequestParser
|
|
186
|
+
get req(): RequestParser<Path>;
|
|
196
187
|
protected set params(params: Record<string, any>);
|
|
197
188
|
/**
|
|
198
189
|
* Set response body to be passed between middlewares or returned as final output.
|
package/core/request.d.ts
CHANGED
|
@@ -1,24 +1,7 @@
|
|
|
1
|
+
import { ExtractParamsFromPath, FormDataOptions, HTTPMethod, NetAddr, PathType } from "../types/index.js";
|
|
1
2
|
import type { UrlRef } from "../utils/url.js";
|
|
2
3
|
import { TezXServeOptions } from "./server.js";
|
|
3
|
-
export
|
|
4
|
-
maxSize?: number;
|
|
5
|
-
allowedTypes?: string[];
|
|
6
|
-
sanitized?: boolean;
|
|
7
|
-
maxFiles?: number;
|
|
8
|
-
};
|
|
9
|
-
type TransportType = "tcp" | "udp" | "unix" | "pipe" | "unixpacket";
|
|
10
|
-
export type NetAddr = {
|
|
11
|
-
transport?: TransportType;
|
|
12
|
-
family?: "IPv4" | "IPv6" | "Unix";
|
|
13
|
-
address?: string;
|
|
14
|
-
port?: number;
|
|
15
|
-
};
|
|
16
|
-
export type ConnAddress = {
|
|
17
|
-
remoteAddr: NetAddr;
|
|
18
|
-
localAddr: NetAddr;
|
|
19
|
-
};
|
|
20
|
-
export type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "OPTIONS" | "PATCH" | "HEAD" | "ALL" | "TRACE" | "CONNECT" | string;
|
|
21
|
-
export declare class Request {
|
|
4
|
+
export declare class Request<Path extends PathType = any> {
|
|
22
5
|
/**
|
|
23
6
|
* Full request URL including protocol and query string
|
|
24
7
|
* @type {string}
|
|
@@ -44,7 +27,7 @@ export declare class Request {
|
|
|
44
27
|
* @param name - The parameter name.
|
|
45
28
|
* @returns The parameter value if found, or undefined.
|
|
46
29
|
*/
|
|
47
|
-
readonly params:
|
|
30
|
+
readonly params: ExtractParamsFromPath<Path>;
|
|
48
31
|
/**
|
|
49
32
|
* Represents the remote address details of a connected client.
|
|
50
33
|
*
|
|
@@ -151,4 +134,3 @@ export declare class Request {
|
|
|
151
134
|
*/
|
|
152
135
|
formData(options?: FormDataOptions): Promise<Record<string, any>>;
|
|
153
136
|
}
|
|
154
|
-
export {};
|
package/core/router.d.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
export type ctx<T extends Record<string, any> = {}> = Context<T> & T;
|
|
5
|
-
export type NextCallback = () => Promise<any>;
|
|
6
|
-
export type CallbackReturn = Promise<Response> | Response;
|
|
7
|
-
export type Callback<T extends Record<string, any> = {}> = (ctx: ctx<T>) => CallbackReturn;
|
|
8
|
-
export type Middleware<T extends Record<string, any> = {}> = (ctx: ctx<T>, next: NextCallback) => Promise<Response | void> | Response | NextCallback;
|
|
9
|
-
export type PathType = string | RegExp;
|
|
1
|
+
import { Callback, DuplicateMiddlewares, HTTPMethod, Middleware, PathType, StaticServeOption, UniqueMiddlewares } from "../types/index.js";
|
|
2
|
+
import { Context } from "./context.js";
|
|
3
|
+
import MiddlewareConfigure from "./MiddlewareConfigure.js";
|
|
10
4
|
export type RouterConfig = {
|
|
11
5
|
/**
|
|
12
6
|
* `env` allows you to define environment variables for the router.
|
|
@@ -31,10 +25,6 @@ export declare class TrieRouter {
|
|
|
31
25
|
isParam: boolean;
|
|
32
26
|
constructor(pathname?: string);
|
|
33
27
|
}
|
|
34
|
-
export type StaticServeOption = {
|
|
35
|
-
cacheControl?: string;
|
|
36
|
-
headers?: ResponseHeaders;
|
|
37
|
-
};
|
|
38
28
|
export type RouterHandler<T extends Record<string, any>> = {
|
|
39
29
|
callback: Callback<T>;
|
|
40
30
|
paramNames: string[];
|
|
@@ -80,9 +70,9 @@ export declare class Router<T extends Record<string, any> = {}> extends Middlewa
|
|
|
80
70
|
* // With multiple middlewares
|
|
81
71
|
* app.get('/admin', [authMiddleware, adminMiddleware], (ctx) => { ... });
|
|
82
72
|
*/
|
|
83
|
-
get(path:
|
|
84
|
-
get(path:
|
|
85
|
-
get(path:
|
|
73
|
+
get<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, callback: Callback<T & U, Path>): this;
|
|
74
|
+
get<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, middleware: Middleware<T & U, Path>, callback: Callback<T & U, Path>): this;
|
|
75
|
+
get<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, middlewares: Middleware<T & U, Path>[], callback: Callback<T & U, Path>): this;
|
|
86
76
|
/**
|
|
87
77
|
* Registers a Server-Sent Events (SSE) route handler for the given path.
|
|
88
78
|
*
|
|
@@ -115,63 +105,63 @@ export declare class Router<T extends Record<string, any> = {}> extends Middlewa
|
|
|
115
105
|
* @param {PathType} path - The route path for SSE (e.g. `/events`).
|
|
116
106
|
* @param {(ctx: Context) => any} handler - A handler function that returns a streamed response.
|
|
117
107
|
*/
|
|
118
|
-
sse(path:
|
|
108
|
+
sse<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, handler: (ctx: Context<T & U, Path>) => any): void;
|
|
119
109
|
/**
|
|
120
110
|
* Registers a POST route with optional middleware(s)
|
|
121
111
|
* @param path - URL path pattern
|
|
122
112
|
* @param args - Handler callback or middleware(s) + handler
|
|
123
113
|
*/
|
|
124
|
-
post(path:
|
|
125
|
-
post(path:
|
|
126
|
-
post(path:
|
|
114
|
+
post<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, callback: Callback<T & U, Path>): this;
|
|
115
|
+
post<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, middleware: Middleware<T & U, Path>, callback: Callback<T & U, Path>): this;
|
|
116
|
+
post<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, middlewares: Middleware<T & U, Path>[], callback: Callback<T & U, Path>): this;
|
|
127
117
|
/**
|
|
128
118
|
* Registers a PUT route with optional middleware(s)
|
|
129
119
|
* @param path - URL path pattern
|
|
130
120
|
* @param args - Handler callback or middleware(s) + handler
|
|
131
121
|
*/
|
|
132
|
-
put(path:
|
|
133
|
-
put(path:
|
|
134
|
-
put(path:
|
|
122
|
+
put<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, callback: Callback<T & U, Path>): this;
|
|
123
|
+
put<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, middleware: Middleware<T & U, Path>, callback: Callback<T & U, Path>): this;
|
|
124
|
+
put<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, middlewares: Middleware<T & U, Path>[], callback: Callback<T & U, Path>): this;
|
|
135
125
|
/**
|
|
136
126
|
* Registers a PATCH route with optional middleware(s)
|
|
137
127
|
* @param path - URL path pattern
|
|
138
128
|
* @param args - Handler callback or middleware(s) + handler
|
|
139
129
|
*/
|
|
140
|
-
patch(path:
|
|
141
|
-
patch(path:
|
|
142
|
-
patch(path:
|
|
130
|
+
patch<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, callback: Callback<T & U, Path>): this;
|
|
131
|
+
patch<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, middleware: Middleware<T & U, Path>, callback: Callback<T & U, Path>): this;
|
|
132
|
+
patch<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, middlewares: Middleware<T & U, Path>[], callback: Callback<T & U, Path>): this;
|
|
143
133
|
/**
|
|
144
134
|
* Registers a DELETE route with optional middleware(s)
|
|
145
135
|
* @param path - URL path pattern
|
|
146
136
|
* @param args - Handler callback or middleware(s) + handler
|
|
147
137
|
*/
|
|
148
|
-
delete(path:
|
|
149
|
-
delete(path:
|
|
150
|
-
delete(path:
|
|
138
|
+
delete<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, callback: Callback<T & U, Path>): this;
|
|
139
|
+
delete<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, middleware: Middleware<T & U, Path>, callback: Callback<T & U, Path>): this;
|
|
140
|
+
delete<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, middlewares: Middleware<T & U, Path>[], callback: Callback<T & U, Path>): this;
|
|
151
141
|
/**
|
|
152
142
|
* Registers an OPTIONS route (primarily for CORS preflight requests)
|
|
153
143
|
* @param path - URL path pattern
|
|
154
144
|
* @param args - Handler callback or middleware(s) + handler
|
|
155
145
|
*/
|
|
156
|
-
options(path:
|
|
157
|
-
options(path:
|
|
158
|
-
options(path:
|
|
146
|
+
options<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, callback: Callback<T & U, Path>): this;
|
|
147
|
+
options<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, middleware: Middleware<T & U, Path>, callback: Callback<T & U, Path>): this;
|
|
148
|
+
options<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, middlewares: Middleware<T & U, Path>[], callback: Callback<T & U, Path>): this;
|
|
159
149
|
/**
|
|
160
150
|
* Registers a HEAD route (returns headers only)
|
|
161
151
|
* @param path - URL path pattern
|
|
162
152
|
* @param args - Handler callback or middleware(s) + handler
|
|
163
153
|
*/
|
|
164
|
-
head(path:
|
|
165
|
-
head(path:
|
|
166
|
-
head(path:
|
|
154
|
+
head<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, callback: Callback<T & U, Path>): this;
|
|
155
|
+
head<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, middleware: Middleware<T & U, Path>, callback: Callback<T & U, Path>): this;
|
|
156
|
+
head<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, middlewares: Middleware<T & U, Path>[], callback: Callback<T & U, Path>): this;
|
|
167
157
|
/**
|
|
168
158
|
* Registers a route that responds to all HTTP methods
|
|
169
159
|
* @param path - URL path pattern
|
|
170
160
|
* @param args - Handler callback or middleware(s) + handler
|
|
171
161
|
*/
|
|
172
|
-
all(path:
|
|
173
|
-
all(path:
|
|
174
|
-
all(path:
|
|
162
|
+
all<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, callback: Callback<T & U, Path>): this;
|
|
163
|
+
all<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, middleware: Middleware<T & U, Path>, callback: Callback<T & U, Path>): this;
|
|
164
|
+
all<U extends Record<string, any> = {}, Path extends PathType = any>(path: Path, middlewares: Middleware<T & U, Path>[], callback: Callback<T & U, Path>): this;
|
|
175
165
|
/**
|
|
176
166
|
* Generic method registration for custom HTTP methods
|
|
177
167
|
* @param method - HTTP method name (e.g., 'PURGE')
|
|
@@ -182,10 +172,9 @@ export declare class Router<T extends Record<string, any> = {}> extends Middlewa
|
|
|
182
172
|
* // Register custom method
|
|
183
173
|
* server.addRoute('PURGE', '/cache', purgeHandler);
|
|
184
174
|
*/
|
|
185
|
-
addRoute(method: HTTPMethod, path:
|
|
186
|
-
addRoute(method: HTTPMethod, path:
|
|
187
|
-
addRoute(method: HTTPMethod, path:
|
|
188
|
-
addRoute(method: HTTPMethod, path: PathType, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
175
|
+
addRoute<U extends Record<string, any> = {}, Path extends PathType = any>(method: HTTPMethod, path: Path, callback: Callback<T & U, Path>): this;
|
|
176
|
+
addRoute<U extends Record<string, any> = {}, Path extends PathType = any>(method: HTTPMethod, path: Path, middleware: Middleware<T & U, Path>, callback: Callback<T & U, Path>): this;
|
|
177
|
+
addRoute<U extends Record<string, any> = {}, Path extends PathType = any>(method: HTTPMethod, path: Path, middlewares: Middleware<T & U, Path>[], callback: Callback<T & U, Path>): this;
|
|
189
178
|
/**
|
|
190
179
|
* Mount a sub-router at specific path prefix
|
|
191
180
|
* @param path - Base path for the sub-router
|
|
@@ -197,7 +186,7 @@ export declare class Router<T extends Record<string, any> = {}> extends Middlewa
|
|
|
197
186
|
* apiRouter.get('/users', () => { ... });
|
|
198
187
|
* server.addRouter('/api', apiRouter);
|
|
199
188
|
*/
|
|
200
|
-
addRouter(path:
|
|
189
|
+
addRouter<U extends Record<string, any> = {}, Path extends string = any>(path: Path, router: Router<T | U | any>): void;
|
|
201
190
|
/**
|
|
202
191
|
* Create route group with shared path prefix
|
|
203
192
|
* @param prefix - Path prefix for the group
|
|
@@ -209,7 +198,7 @@ export declare class Router<T extends Record<string, any> = {}> extends Middlewa
|
|
|
209
198
|
* group.get('/users', v1UserHandler);
|
|
210
199
|
* });
|
|
211
200
|
*/
|
|
212
|
-
group(prefix:
|
|
201
|
+
group<U extends Record<string, any> = {}, Prefix extends string = any>(prefix: Prefix, callback: (group: Router<T & U>) => void): this;
|
|
213
202
|
/**
|
|
214
203
|
* Register middleware with flexible signature
|
|
215
204
|
* @overload
|
|
@@ -217,14 +206,14 @@ export declare class Router<T extends Record<string, any> = {}> extends Middlewa
|
|
|
217
206
|
* @param middlewares - Middleware(s) to register
|
|
218
207
|
* @param [callback] - Optional sub-router or handler
|
|
219
208
|
*/
|
|
220
|
-
use(path:
|
|
221
|
-
use(path:
|
|
222
|
-
use(path:
|
|
223
|
-
use(path:
|
|
224
|
-
use(path:
|
|
225
|
-
use(middlewares: Middleware<T>[], callback: Callback<T> | Router<T | any>): this;
|
|
226
|
-
use(middleware: Middleware<T>, callback: Callback<T> | Router<T | any>): this;
|
|
227
|
-
use(middlewares: Middleware<T>[]): this;
|
|
228
|
-
use(middleware: Middleware<T>): this;
|
|
229
|
-
use(callback: Callback<T> | Router<T | any>): this;
|
|
209
|
+
use<U extends Record<string, any> = {}, Path extends string = any>(path: Path, middlewares: Middleware<T & U, Path>[], callback: Callback<T & U, Path> | Router<T & U | any>): this;
|
|
210
|
+
use<U extends Record<string, any> = {}, Path extends string = any>(path: Path, middleware: Middleware<T & U, Path>, callback: Callback<T & U, Path> | Router<T & U | any>): this;
|
|
211
|
+
use<U extends Record<string, any> = {}, Path extends string = any>(path: Path, middlewares: Middleware<T & U, Path>[]): this;
|
|
212
|
+
use<U extends Record<string, any> = {}, Path extends string = any>(path: Path, middlewares: Middleware<T & U, Path>): this;
|
|
213
|
+
use<U extends Record<string, any> = {}, Path extends string = any>(path: Path, callback: Callback<T & U, Path> | Router<T & U | any>): this;
|
|
214
|
+
use<U extends Record<string, any> = {}, Path extends string = any>(middlewares: Middleware<T & U, Path>[], callback: Callback<T & U, Path> | Router<T & U | any>): this;
|
|
215
|
+
use<U extends Record<string, any> = {}, Path extends string = any>(middleware: Middleware<T & U, Path>, callback: Callback<T & U, Path> | Router<T & U | any>): this;
|
|
216
|
+
use<U extends Record<string, any> = {}, Path extends string = any>(middlewares: Middleware<T & U, Path>[]): this;
|
|
217
|
+
use<U extends Record<string, any> = {}, Path extends string = any>(middleware: Middleware<T & U, Path>): this;
|
|
218
|
+
use<U extends Record<string, any> = {}, Path extends string = any>(callback: Callback<T & U, Path> | Router<T & U | any>): this;
|
|
230
219
|
}
|
package/core/router.js
CHANGED
|
@@ -213,7 +213,7 @@ export class Router extends MiddlewareConfigure {
|
|
|
213
213
|
if (!GlobalConfig.overwriteMethod && handler.has(method))
|
|
214
214
|
return;
|
|
215
215
|
return handler.set(method, {
|
|
216
|
-
callback,
|
|
216
|
+
callback: callback,
|
|
217
217
|
paramNames: [],
|
|
218
218
|
regex: regex,
|
|
219
219
|
middlewares: finalMiddleware
|
|
@@ -238,7 +238,7 @@ export class Router extends MiddlewareConfigure {
|
|
|
238
238
|
if (!GlobalConfig.overwriteMethod && handler.has(method))
|
|
239
239
|
return;
|
|
240
240
|
return handler.set(method, {
|
|
241
|
-
callback,
|
|
241
|
+
callback: callback,
|
|
242
242
|
regex: regex,
|
|
243
243
|
paramNames: paramNames,
|
|
244
244
|
middlewares: finalMiddleware
|
package/core/server.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { ConnAddress, HTTPMethod, Middleware } from "../types/index.js";
|
|
1
2
|
import { Context } from "./context.js";
|
|
2
|
-
import {
|
|
3
|
-
import { Middleware, Router, RouterConfig } from "./router.js";
|
|
3
|
+
import { Router, RouterConfig } from "./router.js";
|
|
4
4
|
export type TezXServeOptions = {
|
|
5
5
|
connInfo: ConnAddress;
|
|
6
6
|
};
|
package/helper/common.js
CHANGED
|
@@ -3,6 +3,12 @@ export function generateID() {
|
|
|
3
3
|
const random = Math.floor(Math.random() * 0xffffffffffff)
|
|
4
4
|
.toString(16)
|
|
5
5
|
.padStart(12, "0");
|
|
6
|
-
|
|
6
|
+
let pid = Math.floor(Math.random() * 0xffff).toString(16).padStart(4, "0");
|
|
7
|
+
if (typeof Deno !== "undefined" && typeof Deno.pid === "number") {
|
|
8
|
+
pid = (Deno.pid % 0xffff).toString(16).padStart(4, "0");
|
|
9
|
+
}
|
|
10
|
+
else if (typeof process !== "undefined" && typeof process.pid === "number") {
|
|
11
|
+
pid = (process.pid % 0xffff).toString(16).padStart(4, "0");
|
|
12
|
+
}
|
|
7
13
|
return `${timestamp}-${random}-${pid}`;
|
|
8
14
|
}
|
package/helper/index.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
+
import { GlobalConfig } from "../core/config.js";
|
|
1
2
|
import { Environment } from "../core/environment.js";
|
|
3
|
+
import { colorText } from "../utils/colors.js";
|
|
2
4
|
import { sanitizePathSplit } from "../utils/url.js";
|
|
3
5
|
import { generateID } from "./common.js";
|
|
4
|
-
export {
|
|
5
|
-
export type { AdapterType } from "../core/config.js";
|
|
6
|
-
export { Environment } from "../core/environment.js";
|
|
7
|
-
export { sanitizePathSplit } from "../utils/url.js";
|
|
6
|
+
export type { AdapterType } from "../types/index.js";
|
|
8
7
|
export type { UrlRef } from "../utils/url.js";
|
|
9
|
-
export { generateID
|
|
8
|
+
export { colorText, Environment, generateID, GlobalConfig, sanitizePathSplit };
|
|
10
9
|
declare const _default: {
|
|
11
10
|
Environment: typeof Environment;
|
|
11
|
+
colorText: typeof colorText;
|
|
12
12
|
GlobalConfig: {
|
|
13
13
|
new (): {};
|
|
14
|
-
notFound: import("../index.js").Callback;
|
|
15
|
-
onError: <T extends Record<string, any> = {}>(err: string, ctx: import("../index.js").
|
|
14
|
+
notFound: import("../types/index.js").Callback;
|
|
15
|
+
onError: <T extends Record<string, any> = {}>(err: string, ctx: import("../types/index.js").ctx<T>) => Response;
|
|
16
16
|
allowDuplicateMw?: boolean;
|
|
17
17
|
overwriteMethod?: boolean;
|
|
18
18
|
debugMode?: boolean;
|
|
19
19
|
server: any;
|
|
20
|
-
adapter: import("../
|
|
20
|
+
adapter: import("../types/index.js").AdapterType;
|
|
21
21
|
readonly debugging: {
|
|
22
22
|
info: (msg: string, ...args: unknown[]) => void;
|
|
23
23
|
warn: (msg: string, ...args: unknown[]) => void;
|
package/helper/index.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { GlobalConfig } from "../core/config.js";
|
|
2
2
|
import { Environment } from "../core/environment.js";
|
|
3
|
+
import { colorText } from "../utils/colors.js";
|
|
3
4
|
import { sanitizePathSplit } from "../utils/url.js";
|
|
4
5
|
import { generateID } from "./common.js";
|
|
5
|
-
export { GlobalConfig }
|
|
6
|
-
export { Environment } from "../core/environment.js";
|
|
7
|
-
export { sanitizePathSplit } from "../utils/url.js";
|
|
8
|
-
export { generateID } from "./common.js";
|
|
6
|
+
export { colorText, Environment, generateID, GlobalConfig, sanitizePathSplit };
|
|
9
7
|
export default {
|
|
10
8
|
Environment,
|
|
9
|
+
colorText,
|
|
11
10
|
GlobalConfig,
|
|
12
11
|
sanitizePathSplit,
|
|
13
12
|
generateID,
|
package/index.d.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { Router } from "./core/router.js";
|
|
2
2
|
import { TezX } from "./core/server.js";
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
5
|
-
export type {
|
|
6
|
-
export type { AdapterType } from "./
|
|
7
|
-
export type { CookieOptions, ResponseHeaders } from "./core/context.js";
|
|
8
|
-
export type { NetAddr as AddressType, ConnAddress, FormDataOptions, HTTPMethod } from "./core/request.js";
|
|
9
|
-
export { TezX } from "./core/server.js";
|
|
3
|
+
import { compileRegexRoute, regexMatchRoute } from "./utils/regexRouter.js";
|
|
4
|
+
export type { Context as BaseContext } from "./core/context.js";
|
|
5
|
+
export type { RouterConfig } from "./core/router.js";
|
|
6
|
+
export type { AdapterType, NetAddr as AddressType, Callback, CallbackReturn, ConnAddress, ctx as Context, CookieOptions, FormDataOptions, HTTPMethod, Middleware, NextCallback, PathType, ResponseHeaders, StaticServeOption } from "./types/index.js";
|
|
10
7
|
export type { TezXConfig, TezXServeOptions } from "./core/server.js";
|
|
11
8
|
export type { UrlRef } from "./utils/url.js";
|
|
12
|
-
export { regexMatchRoute,
|
|
9
|
+
export { compileRegexRoute, regexMatchRoute, Router, TezX };
|
|
13
10
|
export declare let version: string;
|
|
14
11
|
declare const _default: {
|
|
15
12
|
Router: typeof Router;
|
package/index.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { Router } from "./core/router.js";
|
|
2
2
|
import { TezX } from "./core/server.js";
|
|
3
|
-
import {
|
|
4
|
-
export { Router }
|
|
5
|
-
export
|
|
6
|
-
export { regexMatchRoute, compileRegexRoute };
|
|
7
|
-
export let version = "2.0.8";
|
|
3
|
+
import { compileRegexRoute, regexMatchRoute } from "./utils/regexRouter.js";
|
|
4
|
+
export { compileRegexRoute, regexMatchRoute, Router, TezX };
|
|
5
|
+
export let version = "2.0.11";
|
|
8
6
|
export default {
|
|
9
7
|
Router,
|
|
10
|
-
regexMatchRoute,
|
|
8
|
+
regexMatchRoute,
|
|
9
|
+
compileRegexRoute,
|
|
11
10
|
TezX,
|
|
12
11
|
version,
|
|
13
12
|
};
|
package/middleware/cors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CallbackReturn } from "../core/router.js";
|
|
2
1
|
import { Context, Middleware } from "../index.js";
|
|
2
|
+
import { CallbackReturn } from "../types/index.js";
|
|
3
3
|
export type DetectBotReason = "User-Agent" | "Blacklisted IP" | "Query Parameter" | "Rate Limiting" | "Custom Detector" | "Multiple Indicators";
|
|
4
4
|
export type BotDetectionResult = {
|
|
5
5
|
isBot: boolean;
|
package/middleware/index.d.ts
CHANGED
|
@@ -33,6 +33,6 @@ declare const _default: {
|
|
|
33
33
|
requestTimeout: (options: import("./requestTimeout.js").TimeoutOptions) => import("../index.js").Middleware;
|
|
34
34
|
sanitizeHeaders: (options?: import("./sanitizeHeader.js").SanitizeHeadersOptions) => import("../index.js").Middleware;
|
|
35
35
|
secureHeaders: (options?: import("./secureHeaders.js").SecurityHeaderOptions) => import("../index.js").Middleware;
|
|
36
|
-
xssProtection: (options?: import("./xssProtection.js").XSSProtectionOptions) => (ctx: import("../
|
|
36
|
+
xssProtection: (options?: import("./xssProtection.js").XSSProtectionOptions) => (ctx: import("../index.js").BaseContext, next: import("../index.js").NextCallback) => Promise<any>;
|
|
37
37
|
};
|
|
38
38
|
export default _default;
|
package/middleware/logger.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context } from "../core/context.js";
|
|
2
|
-
import { CallbackReturn, Middleware } from "../
|
|
2
|
+
import { CallbackReturn, Middleware } from "../types/index.js";
|
|
3
3
|
export type RateLimiterOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* 🔴 Maximum allowed requests in the time window
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context } from "../core/context.js";
|
|
2
|
-
import { CallbackReturn, Middleware } from "../
|
|
2
|
+
import { CallbackReturn, Middleware } from "../types/index.js";
|
|
3
3
|
export type TimeoutOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* ⏳ Function to dynamically determine the timeout duration (in milliseconds).
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context } from "../core/context.js";
|
|
2
|
-
import { Middleware } from "../
|
|
2
|
+
import { Middleware } from "../types/index.js";
|
|
3
3
|
export type DynamicHeaderValue = string | ((ctx: Context) => string | undefined);
|
|
4
4
|
export type SecurityHeaderOptions = {
|
|
5
5
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tezx",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.11",
|
|
4
4
|
"description": "TezX is a high-performance, lightweight JavaScript framework designed for speed, scalability, and flexibility. It enables efficient routing, middleware management, and static file serving with minimal configuration. Fully compatible with Node.js, Deno, and Bun.",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -61,13 +61,14 @@
|
|
|
61
61
|
},
|
|
62
62
|
"files": [
|
|
63
63
|
"adapter/",
|
|
64
|
+
"bun/",
|
|
64
65
|
"cjs/",
|
|
65
66
|
"core/",
|
|
66
|
-
"helper/",
|
|
67
|
-
"bun/",
|
|
68
67
|
"deno/",
|
|
68
|
+
"helper/",
|
|
69
69
|
"node/",
|
|
70
70
|
"middleware/",
|
|
71
|
+
"types/",
|
|
71
72
|
"utils/",
|
|
72
73
|
"ws/",
|
|
73
74
|
"index.js",
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export type DuplicateMiddlewares = Middleware<any>[];
|
|
2
|
+
export type UniqueMiddlewares = Set<Middleware<any>>;
|
|
3
|
+
export interface CookieOptions {
|
|
4
|
+
expires?: Date;
|
|
5
|
+
path?: string;
|
|
6
|
+
maxAge?: number;
|
|
7
|
+
domain?: string;
|
|
8
|
+
secure?: boolean;
|
|
9
|
+
httpOnly?: boolean;
|
|
10
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
11
|
+
}
|
|
12
|
+
export type AdapterType = "bun" | "deno" | "node";
|
|
13
|
+
export type ResponseHeaders = Record<string, string>;
|
|
14
|
+
import { Context } from "../core/context.js";
|
|
15
|
+
export type StaticServeOption = {
|
|
16
|
+
cacheControl?: string;
|
|
17
|
+
headers?: ResponseHeaders;
|
|
18
|
+
};
|
|
19
|
+
type ExtractParam<Path extends string> = Path extends `${infer _Start}:${infer Param}/${infer Rest}` ? Param extends `${infer Name}?` ? {
|
|
20
|
+
[K in Name]?: string;
|
|
21
|
+
} & ExtractParam<`/${Rest}`> : {
|
|
22
|
+
[K in Param]: string;
|
|
23
|
+
} & ExtractParam<`/${Rest}`> : Path extends `${infer _Start}:${infer Param}` ? Param extends `${infer Name}?` ? {
|
|
24
|
+
[K in Name]?: string;
|
|
25
|
+
} : {
|
|
26
|
+
[K in Param]: string;
|
|
27
|
+
} : {};
|
|
28
|
+
type ExtractWildcard<Path extends string> = Path extends `${string}*${infer Wildcard}` ? Wildcard extends "" ? {
|
|
29
|
+
"*": string;
|
|
30
|
+
} : {
|
|
31
|
+
[K in Wildcard]: string;
|
|
32
|
+
} : {};
|
|
33
|
+
export type ExtractRouteParams<Path extends string> = ExtractParam<Path> & ExtractWildcard<Path> & Record<string, string>;
|
|
34
|
+
export type ExtractParamsFromPath<Path extends PathType> = (Path extends string ? ExtractRouteParams<Path> : {}) & Record<string, string>;
|
|
35
|
+
export type NextCallback = () => Promise<any>;
|
|
36
|
+
export type CallbackReturn = Promise<Response> | Response;
|
|
37
|
+
export type ctx<T extends Record<string, any> = {}, Path extends PathType = any> = Context<T, Path> & T;
|
|
38
|
+
export type Callback<T extends Record<string, any> = {}, Path extends PathType = any> = (ctx: ctx<T, Path>) => CallbackReturn;
|
|
39
|
+
export type Middleware<T extends Record<string, any> = {}, Path extends PathType = any> = (ctx: ctx<T, Path>, next: NextCallback) => Promise<Response | void> | Response | NextCallback;
|
|
40
|
+
export type PathType = string | RegExp;
|
|
41
|
+
export type FormDataOptions = {
|
|
42
|
+
maxSize?: number;
|
|
43
|
+
allowedTypes?: string[];
|
|
44
|
+
sanitized?: boolean;
|
|
45
|
+
maxFiles?: number;
|
|
46
|
+
};
|
|
47
|
+
type TransportType = "tcp" | "udp" | "unix" | "pipe" | "unixpacket";
|
|
48
|
+
export type NetAddr = {
|
|
49
|
+
transport?: TransportType;
|
|
50
|
+
family?: "IPv4" | "IPv6" | "Unix";
|
|
51
|
+
address?: string;
|
|
52
|
+
port?: number;
|
|
53
|
+
};
|
|
54
|
+
export type ConnAddress = {
|
|
55
|
+
remoteAddr: NetAddr;
|
|
56
|
+
localAddr: NetAddr;
|
|
57
|
+
};
|
|
58
|
+
export type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "OPTIONS" | "PATCH" | "HEAD" | "ALL" | "TRACE" | "CONNECT" | string;
|
|
59
|
+
export {};
|
package/types/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/utils/debugging.d.ts
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
1
|
export type LogLevel = "info" | "warn" | "error" | "debug" | "success";
|
|
2
2
|
export declare const loggerOutput: (level: LogLevel, message: string, ...args: unknown[]) => void;
|
|
3
|
-
/**
|
|
4
|
-
* A universal logger function that measures and logs the processing time of an operation.
|
|
5
|
-
* @param label - A label to identify the operation being logged.
|
|
6
|
-
* @param callback - The operation to measure and execute.
|
|
7
|
-
*/
|
package/utils/debugging.js
CHANGED
package/utils/regexRouter.d.ts
CHANGED
|
@@ -60,7 +60,7 @@ export declare function addBaseToRegex(basePath: string, routeRegex: RegExp): Re
|
|
|
60
60
|
* const result = regexMatchRoute(regex, url, paramNames);
|
|
61
61
|
* // result = { success: true, params: { userId: "123", postId: "abc" } }
|
|
62
62
|
*/
|
|
63
|
-
export declare function regexMatchRoute(regex: RegExp, url: string, paramNames
|
|
63
|
+
export declare function regexMatchRoute(regex: RegExp, url: string, paramNames?: string[]): {
|
|
64
64
|
params: Record<string, string | null>;
|
|
65
65
|
success: boolean;
|
|
66
66
|
};
|
package/utils/regexRouter.js
CHANGED
|
@@ -41,7 +41,7 @@ export function addBaseToRegex(basePath, routeRegex) {
|
|
|
41
41
|
const finalRegex = new RegExp(`^${combined}$`);
|
|
42
42
|
return finalRegex;
|
|
43
43
|
}
|
|
44
|
-
export function regexMatchRoute(regex, url, paramNames) {
|
|
44
|
+
export function regexMatchRoute(regex, url, paramNames = []) {
|
|
45
45
|
const match = url.match(regex);
|
|
46
46
|
if (!match)
|
|
47
47
|
return { success: false, params: {} };
|
package/utils/staticFile.d.ts
CHANGED
package/ws/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CallbackReturn, Middleware } from "../core/router.js";
|
|
2
1
|
import { Context } from "../index.js";
|
|
2
|
+
import { CallbackReturn, Middleware } from "../types/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Type definition for WebSocket event handlers.
|
|
5
5
|
* @template T - The type of data expected by the handler
|
package/ws/node.js
CHANGED
|
@@ -8,7 +8,7 @@ export class NodeTransport {
|
|
|
8
8
|
maxPayload: options.maxPayload ?? 1048576,
|
|
9
9
|
perMessageDeflate: options.perMessageDeflate ?? false,
|
|
10
10
|
});
|
|
11
|
-
server
|
|
11
|
+
server?.on("upgrade", (request, socket, head) => {
|
|
12
12
|
this.wss?.handleUpgrade(request, socket, head, (ws) => {
|
|
13
13
|
this.wss?.emit("connection", ws, request);
|
|
14
14
|
this.setupHandlers(ws, event, options);
|