tezx 1.0.56 → 1.0.58
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/adapter/bun.d.ts +96 -2
- package/adapter/bun.js +76 -58
- package/adapter/deno.d.ts +6 -2
- package/adapter/deno.js +17 -12
- package/adapter/node.d.ts +17 -2
- package/adapter/node.js +22 -13
- package/cjs/adapter/bun.js +76 -58
- package/cjs/adapter/deno.js +17 -12
- package/cjs/adapter/node.js +22 -13
- package/cjs/index.js +1 -1
- package/cjs/middleware/detectBot.js +0 -1
- package/cjs/ws/deno.js +4 -5
- package/cjs/ws/index.js +2 -2
- package/core/context.d.ts +2 -2
- package/core/request.d.ts +7 -7
- package/core/server.d.ts +2 -2
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/middleware/basicAuth.d.ts +0 -1
- package/middleware/detectBot.d.ts +1 -3
- package/middleware/detectBot.js +0 -1
- package/middleware/rateLimiter.d.ts +0 -1
- package/package.json +1 -1
- package/ws/deno.d.ts +1 -1
- package/ws/deno.js +4 -5
- package/ws/index.d.ts +1 -1
- package/ws/index.js +2 -2
package/adapter/bun.d.ts
CHANGED
|
@@ -1,4 +1,98 @@
|
|
|
1
1
|
import { TezX } from "../core/server.js";
|
|
2
|
-
export declare function bunAdapter<T extends Record<string, any> = {}>(TezX: TezX<T
|
|
3
|
-
|
|
2
|
+
export declare function bunAdapter<T extends Record<string, any> = {}>(TezX: TezX<T>, options?: {
|
|
3
|
+
/**
|
|
4
|
+
* If set, the HTTP server will listen on a unix socket instead of a port.
|
|
5
|
+
* (Cannot be used with hostname+port)
|
|
6
|
+
*/
|
|
7
|
+
unix: string;
|
|
8
|
+
} | {
|
|
9
|
+
/**
|
|
10
|
+
* What is the maximum size of a request body? (in bytes)
|
|
11
|
+
* @default 1024 * 1024 * 128 // 128MB
|
|
12
|
+
*/
|
|
13
|
+
maxRequestBodySize?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Render contextual errors? This enables bun's error page
|
|
16
|
+
* @default process.env.NODE_ENV !== 'production'
|
|
17
|
+
*/
|
|
18
|
+
development?: boolean | {
|
|
19
|
+
/**
|
|
20
|
+
* Enable Hot Module Replacement for routes (including React Fast Refresh, if React is in use)
|
|
21
|
+
*
|
|
22
|
+
* @default true if process.env.NODE_ENV !== 'production'
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
hmr?: boolean;
|
|
26
|
+
};
|
|
27
|
+
error?: (s: Bun.Serve, error: Error) => Response | Promise<Response> | void | Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Uniquely identify a server instance with an ID
|
|
30
|
+
*
|
|
31
|
+
* ### When bun is started with the `--hot` flag
|
|
32
|
+
*
|
|
33
|
+
* This string will be used to hot reload the server without interrupting
|
|
34
|
+
* pending requests or websockets. If not provided, a value will be
|
|
35
|
+
* generated. To disable hot reloading, set this value to `null`.
|
|
36
|
+
*
|
|
37
|
+
* ### When bun is not started with the `--hot` flag
|
|
38
|
+
*
|
|
39
|
+
* This string will currently do nothing. But in the future it could be useful for logs or metrics.
|
|
40
|
+
*/
|
|
41
|
+
id?: string | null;
|
|
42
|
+
/**
|
|
43
|
+
* What port should the server listen on?
|
|
44
|
+
* @default process.env.PORT || "3000"
|
|
45
|
+
*/
|
|
46
|
+
port?: string | number;
|
|
47
|
+
/**
|
|
48
|
+
* Whether the `SO_REUSEPORT` flag should be set.
|
|
49
|
+
*
|
|
50
|
+
* This allows multiple processes to bind to the same port, which is useful for load balancing.
|
|
51
|
+
*
|
|
52
|
+
* @default false
|
|
53
|
+
*/
|
|
54
|
+
reusePort?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Whether the `IPV6_V6ONLY` flag should be set.
|
|
57
|
+
* @default false
|
|
58
|
+
*/
|
|
59
|
+
ipv6Only?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* What hostname should the server listen on?
|
|
62
|
+
*
|
|
63
|
+
* @default
|
|
64
|
+
* ```js
|
|
65
|
+
* "0.0.0.0" // listen on all interfaces
|
|
66
|
+
* ```
|
|
67
|
+
* @example
|
|
68
|
+
* ```js
|
|
69
|
+
* "127.0.0.1" // Only listen locally
|
|
70
|
+
* ```
|
|
71
|
+
* @example
|
|
72
|
+
* ```js
|
|
73
|
+
* "remix.run" // Only listen on remix.run
|
|
74
|
+
* ````
|
|
75
|
+
*
|
|
76
|
+
* note: hostname should not include a {@link port}
|
|
77
|
+
*/
|
|
78
|
+
hostname?: string;
|
|
79
|
+
/**
|
|
80
|
+
* If set, the HTTP server will listen on a unix socket instead of a port.
|
|
81
|
+
* (Cannot be used with hostname+port)
|
|
82
|
+
*/
|
|
83
|
+
unix?: never;
|
|
84
|
+
/**
|
|
85
|
+
* Sets the the number of seconds to wait before timing out a connection
|
|
86
|
+
* due to inactivity.
|
|
87
|
+
*
|
|
88
|
+
* Default is `10` seconds.
|
|
89
|
+
*/
|
|
90
|
+
idleTimeout?: number;
|
|
91
|
+
tls?: Bun.TLSOptions | Bun.TLSOptions[];
|
|
92
|
+
}): {
|
|
93
|
+
listen: {
|
|
94
|
+
(callback?: (message: string) => void): any;
|
|
95
|
+
(port?: number): any;
|
|
96
|
+
(port?: number, callback?: (message: string) => void): any;
|
|
97
|
+
};
|
|
4
98
|
};
|
package/adapter/bun.js
CHANGED
|
@@ -1,72 +1,90 @@
|
|
|
1
1
|
import { GlobalConfig } from "../core/config.js";
|
|
2
2
|
import { Context } from "../core/context.js";
|
|
3
|
-
export function bunAdapter(TezX) {
|
|
4
|
-
function listen(
|
|
3
|
+
export function bunAdapter(TezX, options = {}) {
|
|
4
|
+
function listen(...arg) {
|
|
5
|
+
let port = typeof arg?.[0] === "number" ? arg?.[0] : undefined;
|
|
6
|
+
let callback = typeof arg[0] == "function" ? arg[0] : arg?.[1];
|
|
5
7
|
const serve = typeof Bun !== "undefined" ? Bun.serve : null;
|
|
6
8
|
try {
|
|
7
9
|
if (!serve) {
|
|
8
10
|
throw new Error("Bun is not find");
|
|
9
11
|
}
|
|
10
12
|
GlobalConfig.adapter = "bun";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
let server;
|
|
14
|
+
server =
|
|
15
|
+
options?.unix || typeof options?.unix == "string"
|
|
16
|
+
? serve({
|
|
17
|
+
unix: options?.unix,
|
|
18
|
+
fetch: () => {
|
|
19
|
+
return new Response("4004");
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
: serve({
|
|
23
|
+
error: (error) => {
|
|
24
|
+
return (options?.error)(server, error);
|
|
25
|
+
},
|
|
26
|
+
development: options?.development,
|
|
27
|
+
hostname: options?.hostname,
|
|
28
|
+
id: options?.id,
|
|
29
|
+
idleTimeout: options?.idleTimeout,
|
|
30
|
+
ipv6Only: options?.ipv6Only,
|
|
31
|
+
maxRequestBodySize: options?.maxRequestBodySize,
|
|
32
|
+
reusePort: options?.reusePort,
|
|
33
|
+
tls: options?.tls,
|
|
34
|
+
port: options?.port || port,
|
|
35
|
+
async fetch(req) {
|
|
36
|
+
let options = {
|
|
37
|
+
connInfo: {
|
|
38
|
+
remoteAddr: server.requestIP(req),
|
|
39
|
+
localAddr: server.address,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
const response = await TezX.serve(req, options);
|
|
43
|
+
if (typeof response?.websocket == "function" &&
|
|
44
|
+
response.ctx instanceof Context &&
|
|
45
|
+
response.ctx.wsProtocol) {
|
|
46
|
+
let websocket = response?.websocket(response?.ctx);
|
|
47
|
+
const upgradeSuccess = server.upgrade(req, {
|
|
48
|
+
data: { ...websocket },
|
|
49
|
+
});
|
|
50
|
+
if (upgradeSuccess)
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
if (response instanceof Response) {
|
|
54
|
+
return response;
|
|
55
|
+
}
|
|
56
|
+
return new Response(response.body ?? null, {
|
|
57
|
+
status: response.status ?? 200,
|
|
58
|
+
statusText: response.statusText || "",
|
|
59
|
+
headers: new Headers(response.headers ?? {}),
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
websocket: {
|
|
63
|
+
open(ws) {
|
|
64
|
+
return ws.data?.open?.(ws);
|
|
65
|
+
},
|
|
66
|
+
message(ws, msg) {
|
|
67
|
+
return ws.data?.message?.(ws, msg);
|
|
68
|
+
},
|
|
69
|
+
close(ws, code, reason) {
|
|
70
|
+
return ws.data?.close?.(ws, { code, reason });
|
|
71
|
+
},
|
|
72
|
+
ping(ws, data) {
|
|
73
|
+
return ws.data?.ping?.(ws, data);
|
|
74
|
+
},
|
|
75
|
+
pong(ws, data) {
|
|
76
|
+
return ws.data?.pong?.(ws, data);
|
|
77
|
+
},
|
|
78
|
+
drain(ws) {
|
|
79
|
+
return ws.data?.drain?.(ws);
|
|
80
|
+
},
|
|
18
81
|
},
|
|
19
|
-
};
|
|
20
|
-
const response = await TezX.serve(req, options);
|
|
21
|
-
if (typeof response?.websocket == "function" &&
|
|
22
|
-
response.ctx instanceof Context &&
|
|
23
|
-
response.ctx.wsProtocol) {
|
|
24
|
-
let websocket = response?.websocket(response?.ctx);
|
|
25
|
-
const upgradeSuccess = server.upgrade(req, {
|
|
26
|
-
data: { ...websocket },
|
|
27
|
-
});
|
|
28
|
-
if (upgradeSuccess)
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
if (response instanceof Response) {
|
|
32
|
-
return response;
|
|
33
|
-
}
|
|
34
|
-
return new Response(response.body ?? null, {
|
|
35
|
-
status: response.status ?? 200,
|
|
36
|
-
statusText: response.statusText || "",
|
|
37
|
-
headers: new Headers(response.headers ?? {}),
|
|
38
82
|
});
|
|
39
|
-
},
|
|
40
|
-
websocket: {
|
|
41
|
-
open(ws) {
|
|
42
|
-
return ws.data?.open?.(ws);
|
|
43
|
-
},
|
|
44
|
-
message(ws, msg) {
|
|
45
|
-
return ws.data?.message?.(ws, msg);
|
|
46
|
-
},
|
|
47
|
-
close(ws, code, reason) {
|
|
48
|
-
return ws.data?.close?.(ws, { code, reason });
|
|
49
|
-
},
|
|
50
|
-
ping(ws, data) {
|
|
51
|
-
return ws.data?.ping?.(ws, data);
|
|
52
|
-
},
|
|
53
|
-
pong(ws, data) {
|
|
54
|
-
return ws.data?.pong?.(ws, data);
|
|
55
|
-
},
|
|
56
|
-
drain(ws) {
|
|
57
|
-
return ws.data?.drain?.(ws);
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
83
|
GlobalConfig.server = server;
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
if (typeof callback == "function")
|
|
65
|
-
callback(
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
GlobalConfig.debugging.success(message);
|
|
69
|
-
}
|
|
84
|
+
const message = `\x1b[1m Bun TezX Server running at ${server.url}\x1b[0m`;
|
|
85
|
+
GlobalConfig.debugging.success(message);
|
|
86
|
+
if (typeof callback == "function")
|
|
87
|
+
callback();
|
|
70
88
|
return server;
|
|
71
89
|
}
|
|
72
90
|
catch (err) {
|
package/adapter/deno.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { TezX } from "../core/server.js";
|
|
2
|
-
export declare function denoAdapter<T extends Record<string, any> = {}>(TezX: TezX<T
|
|
3
|
-
listen:
|
|
2
|
+
export declare function denoAdapter<T extends Record<string, any> = {}>(TezX: TezX<T>, options?: Deno.ServeUnixOptions | Deno.ServeTcpOptions | (Deno.ServeTcpOptions & Deno.TlsCertifiedKeyPem)): {
|
|
3
|
+
listen: {
|
|
4
|
+
(callback?: (message: string) => void): any;
|
|
5
|
+
(port?: number): any;
|
|
6
|
+
(port?: number, callback?: (message: string) => void): any;
|
|
7
|
+
};
|
|
4
8
|
};
|
package/adapter/deno.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { GlobalConfig } from "../core/config.js";
|
|
2
|
-
export function denoAdapter(TezX) {
|
|
3
|
-
function listen(
|
|
2
|
+
export function denoAdapter(TezX, options = {}) {
|
|
3
|
+
function listen(...arg) {
|
|
4
|
+
let port = typeof arg?.[0] === "number" ? arg?.[0] : undefined;
|
|
5
|
+
let callback = typeof arg[0] == "function" ? arg[0] : arg?.[1];
|
|
4
6
|
const isDeno = typeof Deno !== "undefined";
|
|
5
7
|
try {
|
|
6
8
|
async function handleRequest(req, connInfo) {
|
|
7
9
|
let remoteAddr = connInfo.remoteAddr;
|
|
8
|
-
let localAddr = { ...server
|
|
10
|
+
let localAddr = { ...server?.addr };
|
|
9
11
|
let address = {
|
|
10
12
|
remoteAddr: {
|
|
11
13
|
port: remoteAddr?.port,
|
|
@@ -33,20 +35,23 @@ export function denoAdapter(TezX) {
|
|
|
33
35
|
headers: new Headers(response.headers ?? {}),
|
|
34
36
|
});
|
|
35
37
|
}
|
|
36
|
-
const server = isDeno
|
|
38
|
+
const server = isDeno
|
|
39
|
+
? options.transport === "unix"
|
|
40
|
+
? Deno.serve(options, handleRequest)
|
|
41
|
+
: Deno.serve({ ...options, port }, handleRequest)
|
|
42
|
+
: null;
|
|
37
43
|
if (!server) {
|
|
38
44
|
throw new Error("Deno is not find");
|
|
39
45
|
}
|
|
40
46
|
GlobalConfig.adapter = "deno";
|
|
41
47
|
GlobalConfig.server = server;
|
|
42
|
-
const protocol =
|
|
43
|
-
const message =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
48
|
+
const protocol = `\x1b[1;34m${options?.cert && options?.key ? "https" : "http"}\x1b[0m`;
|
|
49
|
+
const message = options?.transport !== "unix"
|
|
50
|
+
? `\x1b[1m🚀 Deno TezX Server running at ${protocol}://${(server?.addr).hostname}:${server?.addr?.port}/\x1b[0m`
|
|
51
|
+
: `\x1b[1m🚀 Deno TezX Server running at ${server?.addr?.transport}://${server?.addr?.path}\x1b[0m`;
|
|
52
|
+
GlobalConfig.debugging.success(message);
|
|
53
|
+
if (typeof callback === "function")
|
|
54
|
+
callback();
|
|
50
55
|
return server;
|
|
51
56
|
}
|
|
52
57
|
catch (err) {
|
package/adapter/node.d.ts
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
+
import type { ServerOptions } from "node:http";
|
|
2
|
+
import type { TlsOptions } from "node:tls";
|
|
1
3
|
import { TezX } from "../core/server.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
+
type UnixSocketOptions = ServerOptions & {
|
|
5
|
+
unix?: string;
|
|
6
|
+
enableSSL?: false;
|
|
4
7
|
};
|
|
8
|
+
type SSLOptions = ServerOptions & TlsOptions & {
|
|
9
|
+
enableSSL: true;
|
|
10
|
+
};
|
|
11
|
+
type TezXServerOptions = UnixSocketOptions | SSLOptions;
|
|
12
|
+
export declare function nodeAdapter<T extends Record<string, any> = {}>(TezX: TezX<T>, options?: TezXServerOptions): {
|
|
13
|
+
listen: {
|
|
14
|
+
(callback?: (message: string) => void): any;
|
|
15
|
+
(port?: number): any;
|
|
16
|
+
(port?: number, callback?: (message: string) => void): any;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export {};
|
package/adapter/node.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
1
2
|
import { GlobalConfig } from "../core/config.js";
|
|
2
3
|
import { Context } from "../core/context.js";
|
|
3
|
-
export function nodeAdapter(TezX) {
|
|
4
|
-
function listen(
|
|
5
|
-
|
|
4
|
+
export function nodeAdapter(TezX, options = {}) {
|
|
5
|
+
function listen(...arg) {
|
|
6
|
+
let ssl = options?.enableSSL;
|
|
7
|
+
import(ssl ? "node:https" : 'node:http')
|
|
6
8
|
.then((r) => {
|
|
7
9
|
GlobalConfig.adapter = "node";
|
|
8
|
-
let server = r.createServer(async (req, res) => {
|
|
10
|
+
let server = r.createServer(options, async (req, res) => {
|
|
9
11
|
let address = {};
|
|
10
12
|
if (req.socket) {
|
|
11
13
|
address = {
|
|
@@ -42,21 +44,28 @@ export function nodeAdapter(TezX) {
|
|
|
42
44
|
res.statusMessage = statusText;
|
|
43
45
|
}
|
|
44
46
|
res.writeHead(response.status, headers);
|
|
45
|
-
const { Readable } = await import("stream");
|
|
47
|
+
const { Readable } = await import("node:stream");
|
|
46
48
|
if (response.body instanceof Readable) {
|
|
47
|
-
response.body.pipe(res);
|
|
49
|
+
return response.body.pipe(res);
|
|
48
50
|
}
|
|
49
51
|
else {
|
|
50
|
-
const
|
|
51
|
-
if (
|
|
52
|
-
return res.end(Buffer.from(
|
|
52
|
+
const buffer = await response.arrayBuffer();
|
|
53
|
+
if (buffer.byteLength > 0) {
|
|
54
|
+
return res.end(Buffer.from(buffer));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return res.end();
|
|
53
58
|
}
|
|
54
|
-
res.end();
|
|
55
59
|
}
|
|
56
60
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
const port = typeof arg[0] === "number" ? arg[0] : undefined;
|
|
62
|
+
const callback = typeof arg[0] === "function" ? arg[0] : arg[1];
|
|
63
|
+
server.listen(options?.unix || port || 0, () => {
|
|
64
|
+
const protocol = ssl ? "\x1b[1;35mhttps\x1b[0m" : "\x1b[1;34mhttp\x1b[0m";
|
|
65
|
+
const address = server.address();
|
|
66
|
+
const message = typeof address === "string"
|
|
67
|
+
? `\x1b[1mNodeJS TezX Server running at unix://${address}\x1b[0m`
|
|
68
|
+
: `\x1b[1mNodeJS TezX Server running at ${protocol}://localhost:${address?.port}/\x1b[0m`;
|
|
60
69
|
GlobalConfig.server = server;
|
|
61
70
|
if (typeof callback == "function") {
|
|
62
71
|
callback(message);
|
package/cjs/adapter/bun.js
CHANGED
|
@@ -3,73 +3,91 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.bunAdapter = bunAdapter;
|
|
4
4
|
const config_js_1 = require("../core/config.js");
|
|
5
5
|
const context_js_1 = require("../core/context.js");
|
|
6
|
-
function bunAdapter(TezX) {
|
|
7
|
-
function listen(
|
|
6
|
+
function bunAdapter(TezX, options = {}) {
|
|
7
|
+
function listen(...arg) {
|
|
8
|
+
let port = typeof arg?.[0] === "number" ? arg?.[0] : undefined;
|
|
9
|
+
let callback = typeof arg[0] == "function" ? arg[0] : arg?.[1];
|
|
8
10
|
const serve = typeof Bun !== "undefined" ? Bun.serve : null;
|
|
9
11
|
try {
|
|
10
12
|
if (!serve) {
|
|
11
13
|
throw new Error("Bun is not find");
|
|
12
14
|
}
|
|
13
15
|
config_js_1.GlobalConfig.adapter = "bun";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
let server;
|
|
17
|
+
server =
|
|
18
|
+
options?.unix || typeof options?.unix == "string"
|
|
19
|
+
? serve({
|
|
20
|
+
unix: options?.unix,
|
|
21
|
+
fetch: () => {
|
|
22
|
+
return new Response("4004");
|
|
23
|
+
},
|
|
24
|
+
})
|
|
25
|
+
: serve({
|
|
26
|
+
error: (error) => {
|
|
27
|
+
return (options?.error)(server, error);
|
|
28
|
+
},
|
|
29
|
+
development: options?.development,
|
|
30
|
+
hostname: options?.hostname,
|
|
31
|
+
id: options?.id,
|
|
32
|
+
idleTimeout: options?.idleTimeout,
|
|
33
|
+
ipv6Only: options?.ipv6Only,
|
|
34
|
+
maxRequestBodySize: options?.maxRequestBodySize,
|
|
35
|
+
reusePort: options?.reusePort,
|
|
36
|
+
tls: options?.tls,
|
|
37
|
+
port: options?.port || port,
|
|
38
|
+
async fetch(req) {
|
|
39
|
+
let options = {
|
|
40
|
+
connInfo: {
|
|
41
|
+
remoteAddr: server.requestIP(req),
|
|
42
|
+
localAddr: server.address,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
const response = await TezX.serve(req, options);
|
|
46
|
+
if (typeof response?.websocket == "function" &&
|
|
47
|
+
response.ctx instanceof context_js_1.Context &&
|
|
48
|
+
response.ctx.wsProtocol) {
|
|
49
|
+
let websocket = response?.websocket(response?.ctx);
|
|
50
|
+
const upgradeSuccess = server.upgrade(req, {
|
|
51
|
+
data: { ...websocket },
|
|
52
|
+
});
|
|
53
|
+
if (upgradeSuccess)
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
if (response instanceof Response) {
|
|
57
|
+
return response;
|
|
58
|
+
}
|
|
59
|
+
return new Response(response.body ?? null, {
|
|
60
|
+
status: response.status ?? 200,
|
|
61
|
+
statusText: response.statusText || "",
|
|
62
|
+
headers: new Headers(response.headers ?? {}),
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
websocket: {
|
|
66
|
+
open(ws) {
|
|
67
|
+
return ws.data?.open?.(ws);
|
|
68
|
+
},
|
|
69
|
+
message(ws, msg) {
|
|
70
|
+
return ws.data?.message?.(ws, msg);
|
|
71
|
+
},
|
|
72
|
+
close(ws, code, reason) {
|
|
73
|
+
return ws.data?.close?.(ws, { code, reason });
|
|
74
|
+
},
|
|
75
|
+
ping(ws, data) {
|
|
76
|
+
return ws.data?.ping?.(ws, data);
|
|
77
|
+
},
|
|
78
|
+
pong(ws, data) {
|
|
79
|
+
return ws.data?.pong?.(ws, data);
|
|
80
|
+
},
|
|
81
|
+
drain(ws) {
|
|
82
|
+
return ws.data?.drain?.(ws);
|
|
83
|
+
},
|
|
21
84
|
},
|
|
22
|
-
};
|
|
23
|
-
const response = await TezX.serve(req, options);
|
|
24
|
-
if (typeof response?.websocket == "function" &&
|
|
25
|
-
response.ctx instanceof context_js_1.Context &&
|
|
26
|
-
response.ctx.wsProtocol) {
|
|
27
|
-
let websocket = response?.websocket(response?.ctx);
|
|
28
|
-
const upgradeSuccess = server.upgrade(req, {
|
|
29
|
-
data: { ...websocket },
|
|
30
|
-
});
|
|
31
|
-
if (upgradeSuccess)
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
if (response instanceof Response) {
|
|
35
|
-
return response;
|
|
36
|
-
}
|
|
37
|
-
return new Response(response.body ?? null, {
|
|
38
|
-
status: response.status ?? 200,
|
|
39
|
-
statusText: response.statusText || "",
|
|
40
|
-
headers: new Headers(response.headers ?? {}),
|
|
41
85
|
});
|
|
42
|
-
},
|
|
43
|
-
websocket: {
|
|
44
|
-
open(ws) {
|
|
45
|
-
return ws.data?.open?.(ws);
|
|
46
|
-
},
|
|
47
|
-
message(ws, msg) {
|
|
48
|
-
return ws.data?.message?.(ws, msg);
|
|
49
|
-
},
|
|
50
|
-
close(ws, code, reason) {
|
|
51
|
-
return ws.data?.close?.(ws, { code, reason });
|
|
52
|
-
},
|
|
53
|
-
ping(ws, data) {
|
|
54
|
-
return ws.data?.ping?.(ws, data);
|
|
55
|
-
},
|
|
56
|
-
pong(ws, data) {
|
|
57
|
-
return ws.data?.pong?.(ws, data);
|
|
58
|
-
},
|
|
59
|
-
drain(ws) {
|
|
60
|
-
return ws.data?.drain?.(ws);
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
86
|
config_js_1.GlobalConfig.server = server;
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
if (typeof callback == "function")
|
|
68
|
-
callback(
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
config_js_1.GlobalConfig.debugging.success(message);
|
|
72
|
-
}
|
|
87
|
+
const message = `\x1b[1m Bun TezX Server running at ${server.url}\x1b[0m`;
|
|
88
|
+
config_js_1.GlobalConfig.debugging.success(message);
|
|
89
|
+
if (typeof callback == "function")
|
|
90
|
+
callback();
|
|
73
91
|
return server;
|
|
74
92
|
}
|
|
75
93
|
catch (err) {
|
package/cjs/adapter/deno.js
CHANGED
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.denoAdapter = denoAdapter;
|
|
4
4
|
const config_js_1 = require("../core/config.js");
|
|
5
|
-
function denoAdapter(TezX) {
|
|
6
|
-
function listen(
|
|
5
|
+
function denoAdapter(TezX, options = {}) {
|
|
6
|
+
function listen(...arg) {
|
|
7
|
+
let port = typeof arg?.[0] === "number" ? arg?.[0] : undefined;
|
|
8
|
+
let callback = typeof arg[0] == "function" ? arg[0] : arg?.[1];
|
|
7
9
|
const isDeno = typeof Deno !== "undefined";
|
|
8
10
|
try {
|
|
9
11
|
async function handleRequest(req, connInfo) {
|
|
10
12
|
let remoteAddr = connInfo.remoteAddr;
|
|
11
|
-
let localAddr = { ...server
|
|
13
|
+
let localAddr = { ...server?.addr };
|
|
12
14
|
let address = {
|
|
13
15
|
remoteAddr: {
|
|
14
16
|
port: remoteAddr?.port,
|
|
@@ -36,20 +38,23 @@ function denoAdapter(TezX) {
|
|
|
36
38
|
headers: new Headers(response.headers ?? {}),
|
|
37
39
|
});
|
|
38
40
|
}
|
|
39
|
-
const server = isDeno
|
|
41
|
+
const server = isDeno
|
|
42
|
+
? options.transport === "unix"
|
|
43
|
+
? Deno.serve(options, handleRequest)
|
|
44
|
+
: Deno.serve({ ...options, port }, handleRequest)
|
|
45
|
+
: null;
|
|
40
46
|
if (!server) {
|
|
41
47
|
throw new Error("Deno is not find");
|
|
42
48
|
}
|
|
43
49
|
config_js_1.GlobalConfig.adapter = "deno";
|
|
44
50
|
config_js_1.GlobalConfig.server = server;
|
|
45
|
-
const protocol =
|
|
46
|
-
const message =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
51
|
+
const protocol = `\x1b[1;34m${options?.cert && options?.key ? "https" : "http"}\x1b[0m`;
|
|
52
|
+
const message = options?.transport !== "unix"
|
|
53
|
+
? `\x1b[1m🚀 Deno TezX Server running at ${protocol}://${(server?.addr).hostname}:${server?.addr?.port}/\x1b[0m`
|
|
54
|
+
: `\x1b[1m🚀 Deno TezX Server running at ${server?.addr?.transport}://${server?.addr?.path}\x1b[0m`;
|
|
55
|
+
config_js_1.GlobalConfig.debugging.success(message);
|
|
56
|
+
if (typeof callback === "function")
|
|
57
|
+
callback();
|
|
53
58
|
return server;
|
|
54
59
|
}
|
|
55
60
|
catch (err) {
|
package/cjs/adapter/node.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.nodeAdapter = nodeAdapter;
|
|
4
|
+
const node_buffer_1 = require("node:buffer");
|
|
4
5
|
const config_js_1 = require("../core/config.js");
|
|
5
6
|
const context_js_1 = require("../core/context.js");
|
|
6
|
-
function nodeAdapter(TezX) {
|
|
7
|
-
function listen(
|
|
8
|
-
|
|
7
|
+
function nodeAdapter(TezX, options = {}) {
|
|
8
|
+
function listen(...arg) {
|
|
9
|
+
let ssl = options?.enableSSL;
|
|
10
|
+
Promise.resolve(`${ssl ? "node:https" : 'node:http'}`).then(s => require(s)).then((r) => {
|
|
9
11
|
config_js_1.GlobalConfig.adapter = "node";
|
|
10
|
-
let server = r.createServer(async (req, res) => {
|
|
12
|
+
let server = r.createServer(options, async (req, res) => {
|
|
11
13
|
let address = {};
|
|
12
14
|
if (req.socket) {
|
|
13
15
|
address = {
|
|
@@ -44,21 +46,28 @@ function nodeAdapter(TezX) {
|
|
|
44
46
|
res.statusMessage = statusText;
|
|
45
47
|
}
|
|
46
48
|
res.writeHead(response.status, headers);
|
|
47
|
-
const { Readable } = await Promise.resolve().then(() => require("stream"));
|
|
49
|
+
const { Readable } = await Promise.resolve().then(() => require("node:stream"));
|
|
48
50
|
if (response.body instanceof Readable) {
|
|
49
|
-
response.body.pipe(res);
|
|
51
|
+
return response.body.pipe(res);
|
|
50
52
|
}
|
|
51
53
|
else {
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
return res.end(Buffer.from(
|
|
54
|
+
const buffer = await response.arrayBuffer();
|
|
55
|
+
if (buffer.byteLength > 0) {
|
|
56
|
+
return res.end(node_buffer_1.Buffer.from(buffer));
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return res.end();
|
|
55
60
|
}
|
|
56
|
-
res.end();
|
|
57
61
|
}
|
|
58
62
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
const port = typeof arg[0] === "number" ? arg[0] : undefined;
|
|
64
|
+
const callback = typeof arg[0] === "function" ? arg[0] : arg[1];
|
|
65
|
+
server.listen(options?.unix || port || 0, () => {
|
|
66
|
+
const protocol = ssl ? "\x1b[1;35mhttps\x1b[0m" : "\x1b[1;34mhttp\x1b[0m";
|
|
67
|
+
const address = server.address();
|
|
68
|
+
const message = typeof address === "string"
|
|
69
|
+
? `\x1b[1mNodeJS TezX Server running at unix://${address}\x1b[0m`
|
|
70
|
+
: `\x1b[1mNodeJS TezX Server running at ${protocol}://localhost:${address?.port}/\x1b[0m`;
|
|
62
71
|
config_js_1.GlobalConfig.server = server;
|
|
63
72
|
if (typeof callback == "function") {
|
|
64
73
|
callback(message);
|
package/cjs/index.js
CHANGED
|
@@ -7,4 +7,4 @@ var server_js_1 = require("./core/server.js");
|
|
|
7
7
|
Object.defineProperty(exports, "TezX", { enumerable: true, get: function () { return server_js_1.TezX; } });
|
|
8
8
|
var params_js_1 = require("./utils/params.js");
|
|
9
9
|
Object.defineProperty(exports, "useParams", { enumerable: true, get: function () { return params_js_1.useParams; } });
|
|
10
|
-
exports.version = "1.0.
|
|
10
|
+
exports.version = "1.0.58";
|
|
@@ -70,7 +70,6 @@ function createRateLimitDefaultStorage() {
|
|
|
70
70
|
return {
|
|
71
71
|
get: (key) => store.get(key),
|
|
72
72
|
set: (key, value) => store.set(key, value),
|
|
73
|
-
delete: (key) => store.delete(key),
|
|
74
73
|
clearExpired: () => {
|
|
75
74
|
const now = Date.now();
|
|
76
75
|
for (const [key, entry] of store.entries()) {
|
package/cjs/ws/deno.js
CHANGED
|
@@ -3,15 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DenoTransport = void 0;
|
|
4
4
|
class DenoTransport {
|
|
5
5
|
async upgrade(ctx, event, options) {
|
|
6
|
-
const { socket, response } = Deno.upgradeWebSocket(ctx.req.rawRequest, {
|
|
7
|
-
|
|
6
|
+
const { socket, response } = (Deno).upgradeWebSocket(ctx.req.rawRequest, {
|
|
7
|
+
protocol: options.protocol,
|
|
8
8
|
idleTimeout: options.idleTimeout,
|
|
9
|
-
headers: {},
|
|
10
9
|
});
|
|
11
|
-
this.setupHandlers(socket, ctx, event
|
|
10
|
+
this.setupHandlers(socket, ctx, event);
|
|
12
11
|
return response;
|
|
13
12
|
}
|
|
14
|
-
setupHandlers(ws, ctx, event
|
|
13
|
+
setupHandlers(ws, ctx, event) {
|
|
15
14
|
ws.onopen = () => event.open?.(ws, ctx);
|
|
16
15
|
ws.onmessage = (e) => event.message?.(ws, e.data);
|
|
17
16
|
ws.onclose = (e) => event.close?.(ws, { code: e.code, reason: e.reason });
|
package/cjs/ws/index.js
CHANGED
|
@@ -8,7 +8,7 @@ function upgradeWebSocket(callback, options = {}) {
|
|
|
8
8
|
const { onUpgradeError = (error, ctx) => {
|
|
9
9
|
ctx.setStatus = 401;
|
|
10
10
|
return ctx.text(error.message);
|
|
11
|
-
},
|
|
11
|
+
}, protocol, idleTimeout = 30000, perMessageDeflate, maxPayload = 1048576, } = options;
|
|
12
12
|
return async (ctx, next) => {
|
|
13
13
|
const upgrade = ctx.req.headers.get("upgrade")?.toLowerCase();
|
|
14
14
|
const connection = ctx.req.headers.get("connection")?.toLowerCase();
|
|
@@ -32,7 +32,7 @@ function upgradeWebSocket(callback, options = {}) {
|
|
|
32
32
|
case "deno":
|
|
33
33
|
return new deno_js_1.DenoTransport().upgrade(ctx, websocketCallback, {
|
|
34
34
|
idleTimeout,
|
|
35
|
-
|
|
35
|
+
protocol,
|
|
36
36
|
});
|
|
37
37
|
case "bun":
|
|
38
38
|
return callback;
|
package/core/context.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { State } from "../utils/state.js";
|
|
2
2
|
import { HeadersParser } from "./header.js";
|
|
3
3
|
import { HTTPMethod, Request } from "./request.js";
|
|
4
|
-
import {
|
|
4
|
+
import { TezXServeOptions } from "./server.js";
|
|
5
5
|
export interface CookieOptions {
|
|
6
6
|
expires?: Date;
|
|
7
7
|
path?: string;
|
|
@@ -48,7 +48,7 @@ export declare class Context<T extends Record<string, any> = {}> {
|
|
|
48
48
|
*/
|
|
49
49
|
state: State;
|
|
50
50
|
protected readonly resBody?: BodyInit | null;
|
|
51
|
-
constructor(req: any, options:
|
|
51
|
+
constructor(req: any, options: TezXServeOptions);
|
|
52
52
|
/**
|
|
53
53
|
* Appends or set a value to an existing header or creates a new one.
|
|
54
54
|
* @param key - Header name.
|
package/core/request.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { UrlRef } from "../utils/url.js";
|
|
2
2
|
import { HeadersParser } from "./header.js";
|
|
3
|
-
import {
|
|
3
|
+
import { TezXServeOptions } from "./server.js";
|
|
4
4
|
export type FormDataOptions = {
|
|
5
5
|
maxSize?: number;
|
|
6
6
|
allowedTypes?: string[];
|
|
7
7
|
sanitized?: boolean;
|
|
8
8
|
maxFiles?: number;
|
|
9
9
|
};
|
|
10
|
-
type TransportType = "tcp" | "udp" | "unix" | "pipe";
|
|
11
|
-
export type
|
|
10
|
+
type TransportType = "tcp" | "udp" | "unix" | "pipe" | "unixpacket";
|
|
11
|
+
export type NetAddr = {
|
|
12
12
|
transport?: TransportType;
|
|
13
13
|
family?: "IPv4" | "IPv6" | "Unix";
|
|
14
14
|
address?: string;
|
|
15
15
|
port?: number;
|
|
16
16
|
};
|
|
17
17
|
export type ConnAddress = {
|
|
18
|
-
remoteAddr:
|
|
19
|
-
localAddr:
|
|
18
|
+
remoteAddr: NetAddr;
|
|
19
|
+
localAddr: NetAddr;
|
|
20
20
|
};
|
|
21
21
|
export type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "OPTIONS" | "PATCH" | "HEAD" | "ALL" | "TRACE" | "CONNECT" | string;
|
|
22
22
|
export declare class Request {
|
|
@@ -56,13 +56,13 @@ export declare class Request {
|
|
|
56
56
|
* ctx.req.remoteAddress
|
|
57
57
|
* ```
|
|
58
58
|
*/
|
|
59
|
-
remoteAddress:
|
|
59
|
+
remoteAddress: NetAddr;
|
|
60
60
|
constructor({ headers, params, req, options, urlRef, }: {
|
|
61
61
|
req: any;
|
|
62
62
|
params: Record<string, any>;
|
|
63
63
|
headers: HeadersParser;
|
|
64
64
|
urlRef: UrlRef;
|
|
65
|
-
options:
|
|
65
|
+
options: TezXServeOptions;
|
|
66
66
|
});
|
|
67
67
|
get headers(): {
|
|
68
68
|
/**
|
package/core/server.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context } from "./context.js";
|
|
2
2
|
import { ConnAddress, HTTPMethod } from "./request.js";
|
|
3
3
|
import { Middleware, Router, RouterConfig } from "./router.js";
|
|
4
|
-
export type
|
|
4
|
+
export type TezXServeOptions = {
|
|
5
5
|
connInfo: ConnAddress;
|
|
6
6
|
};
|
|
7
7
|
export type TezXConfig = {
|
|
@@ -64,7 +64,7 @@ export declare class TezX<T extends Record<string, any> = {}> extends Router<T>
|
|
|
64
64
|
middlewares: Middleware<T>[];
|
|
65
65
|
params: Record<string, string>;
|
|
66
66
|
} | null;
|
|
67
|
-
serve(req: Request, options:
|
|
67
|
+
serve(req: Request, options: TezXServeOptions): Promise<Response | {
|
|
68
68
|
websocket: (props: any) => any;
|
|
69
69
|
ctx: Context;
|
|
70
70
|
}>;
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { Router } from "./core/router.js";
|
|
2
2
|
export type { Callback, ctx as Context, Middleware, NextCallback, RouterConfig, StaticServeOption, } from "./core/router.js";
|
|
3
3
|
export type { CookieOptions, ResponseHeaders } from "./core/context.js";
|
|
4
|
-
export type { AddressType, ConnAddress, FormDataOptions, HTTPMethod, } from "./core/request.js";
|
|
4
|
+
export type { NetAddr as AddressType, ConnAddress, FormDataOptions, HTTPMethod, } from "./core/request.js";
|
|
5
5
|
export { TezX } from "./core/server.js";
|
|
6
6
|
export type { TezXConfig } from "./core/server.js";
|
|
7
7
|
export { useParams } from "./utils/params.js";
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Context, Middleware } from "../index.js";
|
|
2
1
|
import { CallbackReturn } from "../core/router.js";
|
|
2
|
+
import { Context, Middleware } from "../index.js";
|
|
3
3
|
export type DetectBotReason = "User-Agent" | "Blacklisted IP" | "Query Parameter" | "Rate Limiting" | "Custom Detector" | "Multiple Indicators";
|
|
4
4
|
type BotDetectionResult = {
|
|
5
5
|
isBot: boolean;
|
|
@@ -64,7 +64,6 @@ type DetectBotOptions = {
|
|
|
64
64
|
count: number;
|
|
65
65
|
resetTime: number;
|
|
66
66
|
}) => void;
|
|
67
|
-
delete: (key: string) => void;
|
|
68
67
|
clearExpired: () => void;
|
|
69
68
|
};
|
|
70
69
|
/**
|
|
@@ -114,7 +113,6 @@ export declare function createRateLimitDefaultStorage(): {
|
|
|
114
113
|
count: number;
|
|
115
114
|
resetTime: number;
|
|
116
115
|
}>;
|
|
117
|
-
delete: (key: string) => boolean;
|
|
118
116
|
clearExpired: () => void;
|
|
119
117
|
};
|
|
120
118
|
export declare function isRateLimit(ctx: Context, key: string, store: any, maxRequests: number, windowMs: number): {
|
package/middleware/detectBot.js
CHANGED
|
@@ -64,7 +64,6 @@ export function createRateLimitDefaultStorage() {
|
|
|
64
64
|
return {
|
|
65
65
|
get: (key) => store.get(key),
|
|
66
66
|
set: (key, value) => store.set(key, value),
|
|
67
|
-
delete: (key) => store.delete(key),
|
|
68
67
|
clearExpired: () => {
|
|
69
68
|
const now = Date.now();
|
|
70
69
|
for (const [key, entry] of store.entries()) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tezx",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.58",
|
|
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",
|
package/ws/deno.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context } from "../index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { WebSocketEvent, WebSocketOptions } from "./index.js";
|
|
3
3
|
export declare class DenoTransport {
|
|
4
4
|
upgrade(ctx: Context, event: WebSocketEvent, options: WebSocketOptions): Promise<Response>;
|
|
5
5
|
private setupHandlers;
|
package/ws/deno.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
export class DenoTransport {
|
|
2
2
|
async upgrade(ctx, event, options) {
|
|
3
|
-
const { socket, response } = Deno.upgradeWebSocket(ctx.req.rawRequest, {
|
|
4
|
-
|
|
3
|
+
const { socket, response } = (Deno).upgradeWebSocket(ctx.req.rawRequest, {
|
|
4
|
+
protocol: options.protocol,
|
|
5
5
|
idleTimeout: options.idleTimeout,
|
|
6
|
-
headers: {},
|
|
7
6
|
});
|
|
8
|
-
this.setupHandlers(socket, ctx, event
|
|
7
|
+
this.setupHandlers(socket, ctx, event);
|
|
9
8
|
return response;
|
|
10
9
|
}
|
|
11
|
-
setupHandlers(ws, ctx, event
|
|
10
|
+
setupHandlers(ws, ctx, event) {
|
|
12
11
|
ws.onopen = () => event.open?.(ws, ctx);
|
|
13
12
|
ws.onmessage = (e) => event.message?.(ws, e.data);
|
|
14
13
|
ws.onclose = (e) => event.close?.(ws, { code: e.code, reason: e.reason });
|
package/ws/index.d.ts
CHANGED
|
@@ -162,7 +162,7 @@ export type WebSocketOptions = {
|
|
|
162
162
|
/**
|
|
163
163
|
* Supported WebSocket subprotocols. (Deno only)
|
|
164
164
|
*/
|
|
165
|
-
|
|
165
|
+
protocol?: string;
|
|
166
166
|
/**
|
|
167
167
|
* Time (in seconds) after which the WebSocket connection will be closed if idle. (Deno only)
|
|
168
168
|
*/
|
package/ws/index.js
CHANGED
|
@@ -5,7 +5,7 @@ export function upgradeWebSocket(callback, options = {}) {
|
|
|
5
5
|
const { onUpgradeError = (error, ctx) => {
|
|
6
6
|
ctx.setStatus = 401;
|
|
7
7
|
return ctx.text(error.message);
|
|
8
|
-
},
|
|
8
|
+
}, protocol, idleTimeout = 30000, perMessageDeflate, maxPayload = 1048576, } = options;
|
|
9
9
|
return async (ctx, next) => {
|
|
10
10
|
const upgrade = ctx.req.headers.get("upgrade")?.toLowerCase();
|
|
11
11
|
const connection = ctx.req.headers.get("connection")?.toLowerCase();
|
|
@@ -29,7 +29,7 @@ export function upgradeWebSocket(callback, options = {}) {
|
|
|
29
29
|
case "deno":
|
|
30
30
|
return new DenoTransport().upgrade(ctx, websocketCallback, {
|
|
31
31
|
idleTimeout,
|
|
32
|
-
|
|
32
|
+
protocol,
|
|
33
33
|
});
|
|
34
34
|
case "bun":
|
|
35
35
|
return callback;
|