@linebridge/engine-neo 1.0.7 → 1.2.2
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/README.md +2 -3
- package/lib/cookie.d.ts +2 -0
- package/lib/cookie.js +23 -0
- package/lib/engine.d.ts +5 -3
- package/lib/engine.js +14 -9
- package/lib/listen.js +3 -1
- package/lib/request.d.ts +8 -10
- package/lib/request.js +4 -9
- package/lib/request_iterator.d.ts +2 -2
- package/lib/response.d.ts +3 -4
- package/lib/response.js +3 -3
- package/lib/route_register.d.ts +3 -3
- package/lib/route_register.js +14 -48
- package/lib/utils.d.ts +1 -1
- package/lib/uws.js +13 -7
- package/lib/ws/Websocket.d.ts +70 -118
- package/lib/ws/Websocket.js +81 -209
- package/lib/ws/WebsocketRoute.d.ts +86 -0
- package/lib/ws/WebsocketRoute.js +139 -0
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ The official, high-performance HTTP and WebSocket engine for [Linebridge](https:
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
|
|
8
|
+
pnpm add @linebridge/engine-neo
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
@@ -22,5 +22,4 @@ import "@linebridge/engine-neo"
|
|
|
22
22
|
|
|
23
23
|
This project is licensed under the **MIT License**.
|
|
24
24
|
|
|
25
|
-
It includes software developed by uNetworking AB and uWebSockets.js contributors, which is licensed under the **Apache License 2.0**.
|
|
26
|
-
See the [LICENSE](./LICENSE) file for more details.
|
|
25
|
+
It includes software developed by uNetworking AB and uWebSockets.js contributors, which is licensed under the **Apache License 2.0**. See the [LICENSE](./LICENSE) file for more details.
|
package/lib/cookie.d.ts
ADDED
package/lib/cookie.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as crypto from "node:crypto";
|
|
2
|
+
export function sign(value, secret) {
|
|
3
|
+
const mac = crypto
|
|
4
|
+
.createHmac("sha256", secret)
|
|
5
|
+
.update(value)
|
|
6
|
+
.digest("base64")
|
|
7
|
+
.replace(/=+$/, "");
|
|
8
|
+
return `${value}.${mac}`;
|
|
9
|
+
}
|
|
10
|
+
export function unsign(signed_value, secret) {
|
|
11
|
+
const lastDot = signed_value.lastIndexOf(".");
|
|
12
|
+
if (lastDot === -1)
|
|
13
|
+
return undefined;
|
|
14
|
+
const value = signed_value.slice(0, lastDot);
|
|
15
|
+
const expectedSignature = sign(value, secret);
|
|
16
|
+
const expectedBuffer = Buffer.from(expectedSignature);
|
|
17
|
+
const providedBuffer = Buffer.from(signed_value);
|
|
18
|
+
if (expectedBuffer.length === providedBuffer.length &&
|
|
19
|
+
crypto.timingSafeEqual(expectedBuffer, providedBuffer)) {
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
package/lib/engine.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ import uws_wrapper, { type uWebsockets } from "./uws.js";
|
|
|
15
15
|
import RTEngine from "linebridge/classes/RtEngine/index";
|
|
16
16
|
import { EngineAdaptor } from "linebridge/classes/EngineAdaptor/index";
|
|
17
17
|
import { Route } from "linebridge/classes/Route/index";
|
|
18
|
+
import route_register from "./route_register.js";
|
|
19
|
+
import middleware_register from "./register_middleware.js";
|
|
18
20
|
/**
|
|
19
21
|
* Options that control the engine's behaviour.
|
|
20
22
|
*/
|
|
@@ -76,9 +78,9 @@ export declare class NeoEngine extends EngineAdaptor {
|
|
|
76
78
|
/** Gracefully shuts down the server. Bound to the engine instance. */
|
|
77
79
|
close: () => Promise<boolean>;
|
|
78
80
|
/** Registers a route (HTTP method + path + handler). */
|
|
79
|
-
register:
|
|
81
|
+
register: OmitThisParameter<typeof route_register>;
|
|
80
82
|
/** Registers a global middleware that runs before every route handler. */
|
|
81
|
-
register_middleware:
|
|
83
|
+
register_middleware: OmitThisParameter<typeof middleware_register>;
|
|
82
84
|
/**
|
|
83
85
|
* Publish a message to a topic in MQTT syntax to all WebSocket connections on this Server instance.
|
|
84
86
|
* You cannot publish using wildcards, only fully specified topics.
|
|
@@ -91,7 +93,7 @@ export declare class NeoEngine extends EngineAdaptor {
|
|
|
91
93
|
/** Incoming HTTP request handler. Bound to the engine instance. */
|
|
92
94
|
on_request: (native_req: uWebsockets.HttpRequest, native_res: uWebsockets.HttpResponse, route: Route<any, "server"[]>, socket?: uWebsockets.us_socket_context_t | null | undefined) => any;
|
|
93
95
|
/** Middleware/route iteration loop. Bound to the engine instance. */
|
|
94
|
-
request_iterator: (request: Request<any>, response: Response<any>, route: Route<Server<"neo">, "server"[]>, allMiddlewares: Handler<HandlerKind>[], cursor?: number | undefined) => Promise<void>;
|
|
96
|
+
request_iterator: (request: Request<any>, response: Response<any>, route: Route<Server<"neo">, "server"[]>, allMiddlewares: Handler<HandlerKind.middleware>[], cursor?: number | undefined) => Promise<void>;
|
|
95
97
|
/**
|
|
96
98
|
* Decrements the pending request counter and fires the zero-handler
|
|
97
99
|
* when no requests remain in flight.
|
package/lib/engine.js
CHANGED
|
@@ -14,7 +14,7 @@ import toBoolean from "linebridge/utils/toBoolean";
|
|
|
14
14
|
import RTEngine from "linebridge/classes/RtEngine/index";
|
|
15
15
|
import { EngineAdaptor } from "linebridge/classes/EngineAdaptor/index";
|
|
16
16
|
import { Route } from "linebridge/classes/Route/index";
|
|
17
|
-
import
|
|
17
|
+
import Websocket from "./ws/Websocket.js";
|
|
18
18
|
import route_register from "./route_register.js";
|
|
19
19
|
import middleware_register from "./register_middleware.js";
|
|
20
20
|
import listen from "./listen.js";
|
|
@@ -128,7 +128,7 @@ export class NeoEngine extends EngineAdaptor {
|
|
|
128
128
|
upgrade: (res, req, _context) => this.ws.handleUpgrade(req, res),
|
|
129
129
|
// wrap raw uWS websocket with the polyfill so RTEngine gets EventEmitter + helpers
|
|
130
130
|
open: (ws) => {
|
|
131
|
-
const poly = new
|
|
131
|
+
const poly = new Websocket(ws);
|
|
132
132
|
ws.poly = poly;
|
|
133
133
|
//@ts-ignore polyfill context is Object vs RtEngineSocket's typed shape, but runtime is correct
|
|
134
134
|
this.ws.handleConnection(poly);
|
|
@@ -151,12 +151,15 @@ export class NeoEngine extends EngineAdaptor {
|
|
|
151
151
|
// @ts-ignore
|
|
152
152
|
global.websockets = this.ws;
|
|
153
153
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
154
|
+
if (!toBoolean(process.env.LB_SOCKET_MODE)) {
|
|
155
|
+
// create the default route
|
|
156
|
+
const defaultRoute = new Route();
|
|
157
|
+
defaultRoute.method = "any";
|
|
158
|
+
defaultRoute.path = "/*";
|
|
159
|
+
defaultRoute.fn = this._defaultResponse;
|
|
160
|
+
defaultRoute._initialize(this.server);
|
|
161
|
+
this.register(defaultRoute);
|
|
162
|
+
}
|
|
160
163
|
};
|
|
161
164
|
/** Starts the server. Bound to the engine instance. */
|
|
162
165
|
listen = listen.bind(this);
|
|
@@ -200,7 +203,9 @@ export class NeoEngine extends EngineAdaptor {
|
|
|
200
203
|
* Default handler for unmatched routes. Responds with a 404 JSON body.
|
|
201
204
|
*/
|
|
202
205
|
_defaultResponse(req, res) {
|
|
203
|
-
res.status(404)
|
|
206
|
+
res.status(404)
|
|
207
|
+
.setHeader("content-type", "application/json")
|
|
208
|
+
._sendFast(`{"error":"Not found"}`);
|
|
204
209
|
}
|
|
205
210
|
}
|
|
206
211
|
export { uws_wrapper as uWebsockets };
|
package/lib/listen.js
CHANGED
|
@@ -25,7 +25,9 @@ export default async function () {
|
|
|
25
25
|
this.listen_socket = listen_socket;
|
|
26
26
|
// optionally register process-exit listeners for graceful shutdown
|
|
27
27
|
if (this.options.auto_close) {
|
|
28
|
-
EXIT_EVENTS.forEach((type) => process.once(type, () =>
|
|
28
|
+
EXIT_EVENTS.forEach((type) => process.once(type, () => {
|
|
29
|
+
void this.server._fireClose();
|
|
30
|
+
}));
|
|
29
31
|
}
|
|
30
32
|
resolve();
|
|
31
33
|
}
|
package/lib/request.d.ts
CHANGED
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
* body parsing (JSON, text, urlencoded, buffer), cookies, IP resolution,
|
|
6
6
|
* and path/query parameters.
|
|
7
7
|
*/
|
|
8
|
+
import { sign, unsign } from "./cookie.js";
|
|
8
9
|
import type { uWebsockets } from "./uws.js";
|
|
9
|
-
type HttpRequest = uWebsockets.HttpRequest;
|
|
10
|
-
type HttpResponse = uWebsockets.HttpResponse;
|
|
11
10
|
import type { Request as BaseHttpRequest } from "linebridge/classes/Handler/http";
|
|
12
11
|
import type { EngineAdaptor } from "linebridge/classes/EngineAdaptor/index";
|
|
13
12
|
import type { Route } from "linebridge/classes/Route/index";
|
|
@@ -46,9 +45,9 @@ export default class Request<TServer = Server<any>> implements BaseHttpRequest {
|
|
|
46
45
|
/** Parsed query string parameters (lazy). */
|
|
47
46
|
_query_parameters: any;
|
|
48
47
|
/** The raw uWS HttpRequest object. */
|
|
49
|
-
_raw_request: HttpRequest;
|
|
48
|
+
_raw_request: uWebsockets.HttpRequest;
|
|
50
49
|
/** The raw uWS HttpResponse object (needed for `onData` and `getRemoteAddress`). */
|
|
51
|
-
_raw_response: HttpResponse;
|
|
50
|
+
_raw_response: uWebsockets.HttpResponse;
|
|
52
51
|
/** Request headers extracted synchronously. */
|
|
53
52
|
_headers: Record<string, string>;
|
|
54
53
|
/** Whether all body chunks have been received. */
|
|
@@ -74,7 +73,7 @@ export default class Request<TServer = Server<any>> implements BaseHttpRequest {
|
|
|
74
73
|
/**
|
|
75
74
|
* Creates a Request instance from raw uWS objects.
|
|
76
75
|
*/
|
|
77
|
-
static create<TServer extends Server<any>>(route: Route<TServer>, raw_request: HttpRequest, raw_response: HttpResponse): Request<TServer>;
|
|
76
|
+
static create<TServer extends Server<any>>(route: Route<TServer>, raw_request: uWebsockets.HttpRequest, raw_response: uWebsockets.HttpResponse): Request<TServer>;
|
|
78
77
|
/**
|
|
79
78
|
* The engine that owns this request.
|
|
80
79
|
*/
|
|
@@ -82,7 +81,7 @@ export default class Request<TServer = Server<any>> implements BaseHttpRequest {
|
|
|
82
81
|
/**
|
|
83
82
|
* The raw uWS HttpRequest.
|
|
84
83
|
*/
|
|
85
|
-
get raw(): HttpRequest;
|
|
84
|
+
get raw(): uWebsockets.HttpRequest;
|
|
86
85
|
/**
|
|
87
86
|
* Lazily-parsed headers as a plain object.
|
|
88
87
|
* Header names are lowercased by uWS.
|
|
@@ -98,13 +97,13 @@ export default class Request<TServer = Server<any>> implements BaseHttpRequest {
|
|
|
98
97
|
*/
|
|
99
98
|
resume(): this;
|
|
100
99
|
/**
|
|
101
|
-
* Signs a string with a secret
|
|
100
|
+
* Signs a string with a secret
|
|
102
101
|
*/
|
|
103
|
-
sign
|
|
102
|
+
sign: typeof sign;
|
|
104
103
|
/**
|
|
105
104
|
* Unsigns a signed value. Returns the original string or `undefined` on failure.
|
|
106
105
|
*/
|
|
107
|
-
unsign
|
|
106
|
+
unsign: typeof unsign;
|
|
108
107
|
/**
|
|
109
108
|
* Starts the body parser by registering a uWS `onData` callback.
|
|
110
109
|
*
|
|
@@ -168,4 +167,3 @@ export default class Request<TServer = Server<any>> implements BaseHttpRequest {
|
|
|
168
167
|
*/
|
|
169
168
|
get proxy_ip(): string;
|
|
170
169
|
}
|
|
171
|
-
export {};
|
package/lib/request.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* and path/query parameters.
|
|
7
7
|
*/
|
|
8
8
|
import * as cookie from "cookie";
|
|
9
|
+
import { sign, unsign } from "./cookie.js";
|
|
9
10
|
import querystring from "fast-querystring";
|
|
10
|
-
import signature from "cookie-signature";
|
|
11
11
|
/**
|
|
12
12
|
* HTTP Request class wrapping a uWS HttpRequest.
|
|
13
13
|
*
|
|
@@ -138,18 +138,13 @@ export default class Request {
|
|
|
138
138
|
return this;
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
|
-
* Signs a string with a secret
|
|
141
|
+
* Signs a string with a secret
|
|
142
142
|
*/
|
|
143
|
-
sign
|
|
144
|
-
return signature.sign(string, secret);
|
|
145
|
-
}
|
|
143
|
+
sign = sign;
|
|
146
144
|
/**
|
|
147
145
|
* Unsigns a signed value. Returns the original string or `undefined` on failure.
|
|
148
146
|
*/
|
|
149
|
-
unsign
|
|
150
|
-
const unsigned_value = signature.unsign(signed_value, secret);
|
|
151
|
-
return unsigned_value !== false ? unsigned_value : undefined;
|
|
152
|
-
}
|
|
147
|
+
unsign = unsign;
|
|
153
148
|
/**
|
|
154
149
|
* Starts the body parser by registering a uWS `onData` callback.
|
|
155
150
|
*
|
|
@@ -9,7 +9,7 @@ import type Engine from "./engine.js";
|
|
|
9
9
|
import type Request from "./request.js";
|
|
10
10
|
import type Response from "./response.js";
|
|
11
11
|
import type { Route } from "linebridge/classes/Route/index";
|
|
12
|
-
import type { Handler } from "linebridge/classes/Handler/index";
|
|
12
|
+
import type { Handler, HandlerKind } from "linebridge/classes/Handler/index";
|
|
13
13
|
/**
|
|
14
14
|
* Recursively iterates the middleware chain, then calls the route handler.
|
|
15
15
|
*
|
|
@@ -19,4 +19,4 @@ import type { Handler } from "linebridge/classes/Handler/index";
|
|
|
19
19
|
*
|
|
20
20
|
* @param cursor - Zero-based index into the middleware array. Increments on each recursion.
|
|
21
21
|
*/
|
|
22
|
-
export default function (this: Engine, request: Request<any>, response: Response<any>, route: Route<typeof this.server>, allMiddlewares: Handler[], cursor?: number): Promise<void>;
|
|
22
|
+
export default function (this: Engine, request: Request<any>, response: Response<any>, route: Route<typeof this.server>, allMiddlewares: Handler<HandlerKind.middleware>[], cursor?: number): Promise<void>;
|
package/lib/response.d.ts
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import SSEventStream from "./SSEventStream.js";
|
|
9
9
|
import type { uWebsockets } from "./uws.js";
|
|
10
|
-
type HttpResponse = uWebsockets.HttpResponse;
|
|
11
10
|
import type { EngineAdaptor } from "linebridge/classes/EngineAdaptor/index";
|
|
12
11
|
import type { Route } from "linebridge/classes/Route/index";
|
|
13
12
|
import type { Server } from "linebridge/server";
|
|
@@ -39,7 +38,7 @@ export default class Response<TServer = Server<any>> implements BaseHttpResponse
|
|
|
39
38
|
/** The uWS upgrade socket (WebSocket upgrade requests only). */
|
|
40
39
|
_upgrade_socket: any;
|
|
41
40
|
/** The raw uWS HttpResponse object. */
|
|
42
|
-
_raw_response: HttpResponse | null;
|
|
41
|
+
_raw_response: uWebsockets.HttpResponse | null;
|
|
43
42
|
/** HTTP status code (defaults to 200). */
|
|
44
43
|
_status_code: number;
|
|
45
44
|
/** Custom status message (overrides the default from STATUS_CODES). */
|
|
@@ -71,7 +70,7 @@ export default class Response<TServer = Server<any>> implements BaseHttpResponse
|
|
|
71
70
|
* pending request counter, stops body parsing on the paired request, and
|
|
72
71
|
* fires abort/close event listeners.
|
|
73
72
|
*/
|
|
74
|
-
static create<TServer extends Server<any>>(raw_response: HttpResponse, route: Route<TServer>, request: any, socket: any): Response<TServer>;
|
|
73
|
+
static create<TServer extends Server<any>>(raw_response: uWebsockets.HttpResponse, route: Route<TServer>, request: any, socket: any): Response<TServer>;
|
|
75
74
|
/**
|
|
76
75
|
* Registers an event listener on the response.
|
|
77
76
|
* Supported events: `"abort"`, `"close"`, `"finish"`.
|
|
@@ -198,7 +197,7 @@ export default class Response<TServer = Server<any>> implements BaseHttpResponse
|
|
|
198
197
|
/**
|
|
199
198
|
* The raw uWS HttpResponse.
|
|
200
199
|
*/
|
|
201
|
-
get raw(): HttpResponse | null;
|
|
200
|
+
get raw(): uWebsockets.HttpResponse | null;
|
|
202
201
|
/**
|
|
203
202
|
* Whether the response has been aborted by the client.
|
|
204
203
|
*/
|
package/lib/response.js
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* headers, cookies (with signed cookie support), streaming, file serving,
|
|
6
6
|
* Server-Sent Events, redirects, and JSON/HTML shortcuts.
|
|
7
7
|
*/
|
|
8
|
-
import * as cookie from "cookie";
|
|
9
|
-
import signature from "cookie-signature";
|
|
10
8
|
import { STATUS_CODES } from "http";
|
|
9
|
+
import * as cookie from "cookie";
|
|
10
|
+
import { sign } from "./cookie.js";
|
|
11
11
|
import mime_types from "mime-types";
|
|
12
12
|
import SSEventStream from "./SSEventStream.js";
|
|
13
13
|
const stringify = JSON.stringify;
|
|
@@ -237,7 +237,7 @@ export default class Response {
|
|
|
237
237
|
}
|
|
238
238
|
if (sign_cookie && typeof options.secret === "string") {
|
|
239
239
|
options.encode = false;
|
|
240
|
-
value =
|
|
240
|
+
value = sign(value, options.secret);
|
|
241
241
|
}
|
|
242
242
|
if (this._cookies === null) {
|
|
243
243
|
this._cookies = Object.create(null);
|
package/lib/route_register.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
1
|
+
import type { Route } from "linebridge/classes/Route/index";
|
|
2
|
+
import type { NeoEngine } from "./engine.js";
|
|
3
3
|
/**
|
|
4
4
|
* Registers a route with the engine's uWS app.
|
|
5
5
|
*
|
|
@@ -7,4 +7,4 @@ import { RouteAlike } from "linebridge/classes/Route/index";
|
|
|
7
7
|
*
|
|
8
8
|
* @throws {Error} If the engine is not initialized or the route is invalid.
|
|
9
9
|
*/
|
|
10
|
-
export default function (this:
|
|
10
|
+
export default function (this: NeoEngine, route: Route): void;
|
package/lib/route_register.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Route, } from "linebridge/classes/Route/index";
|
|
2
|
-
import { HandlerKind } from "linebridge/classes/Handler/index";
|
|
3
1
|
/**
|
|
4
2
|
* Registers a route with the engine's uWS app.
|
|
5
3
|
*
|
|
@@ -11,57 +9,25 @@ export default function (route) {
|
|
|
11
9
|
if (!this.uws) {
|
|
12
10
|
throw new Error("Engine is not initialized");
|
|
13
11
|
}
|
|
14
|
-
let routeInstance;
|
|
15
|
-
// support passing a class constructor or an already-constructed instance
|
|
16
|
-
if (typeof route === "function") {
|
|
17
|
-
try {
|
|
18
|
-
routeInstance = new route();
|
|
19
|
-
}
|
|
20
|
-
catch (err) {
|
|
21
|
-
console.error(`Failed to construct route class:\n`, err);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
else if (route instanceof Route) {
|
|
26
|
-
routeInstance = route;
|
|
27
|
-
}
|
|
28
|
-
else if (typeof route.fn === "function") {
|
|
29
|
-
routeInstance = new Route();
|
|
30
|
-
routeInstance.kind = HandlerKind.http;
|
|
31
|
-
routeInstance.path = route.path ?? "/";
|
|
32
|
-
routeInstance.method = route.method ?? "get";
|
|
33
|
-
routeInstance.useContexts = route.useContexts ?? [];
|
|
34
|
-
routeInstance.useMiddlewares = route.useMiddlewares ?? [];
|
|
35
|
-
routeInstance.fn = route.fn;
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
throw new Error("Invalid route provided");
|
|
39
|
-
}
|
|
40
|
-
// try to initialize the route
|
|
41
|
-
try {
|
|
42
|
-
routeInstance._initialize(this.server);
|
|
43
|
-
}
|
|
44
|
-
catch (err) {
|
|
45
|
-
console.error(`Failed to initialize route:\n`, err);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
12
|
// normalize DELETE method for uWS compatibility (uWS uses "del" internally)
|
|
49
|
-
if (
|
|
50
|
-
|
|
13
|
+
if (route.method === "delete") {
|
|
14
|
+
route.method = "del";
|
|
51
15
|
}
|
|
52
16
|
// verify the method is a valid uWS route method before registering
|
|
53
|
-
if (typeof this.uws[
|
|
54
|
-
console.warn(`Invalid method (${
|
|
17
|
+
if (typeof this.uws[route.method] !== "function") {
|
|
18
|
+
console.warn(`Invalid method (${route.method}) for route handler [${route.path}]\nSkipping route..`);
|
|
55
19
|
return;
|
|
56
20
|
}
|
|
57
21
|
this.registers.add({
|
|
58
|
-
kind:
|
|
59
|
-
method:
|
|
60
|
-
path:
|
|
61
|
-
useContexts:
|
|
62
|
-
useMiddlewares:
|
|
63
|
-
_source_file:
|
|
64
|
-
handler:
|
|
22
|
+
kind: route.kind,
|
|
23
|
+
method: route.method,
|
|
24
|
+
path: route.path,
|
|
25
|
+
useContexts: route.useContexts,
|
|
26
|
+
useMiddlewares: route.useMiddlewares,
|
|
27
|
+
_source_file: route._source_file,
|
|
28
|
+
handler: route.handler,
|
|
65
29
|
});
|
|
66
|
-
|
|
30
|
+
if (route.kind === "http") {
|
|
31
|
+
this.uws[route.method](route.path, (res, req) => this.on_request(req, res, route));
|
|
32
|
+
}
|
|
67
33
|
}
|
package/lib/utils.d.ts
CHANGED
|
@@ -10,5 +10,5 @@ declare function wrap_object(original: any, target: any): void;
|
|
|
10
10
|
* @param {BufferEncoding} encoding
|
|
11
11
|
* @returns {String} String
|
|
12
12
|
*/
|
|
13
|
-
declare function array_buffer_to_string(array_buffer: ArrayBuffer, encoding?: BufferEncoding):
|
|
13
|
+
declare function array_buffer_to_string(array_buffer: ArrayBuffer, encoding?: BufferEncoding): string;
|
|
14
14
|
export { array_buffer_to_string, wrap_object };
|
package/lib/uws.js
CHANGED
|
@@ -11,17 +11,23 @@
|
|
|
11
11
|
* See the License for the specific language governing permissions and
|
|
12
12
|
* limitations under the License.
|
|
13
13
|
*/
|
|
14
|
-
import
|
|
14
|
+
import os from "node:os";
|
|
15
15
|
let uws_wrapper;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
if (process.env.IS_BUNDLED) {
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
const mod = await import("../uws-wrapper.node");
|
|
19
|
+
uws_wrapper = mod.default ?? mod;
|
|
18
20
|
}
|
|
19
|
-
|
|
21
|
+
else {
|
|
20
22
|
try {
|
|
21
|
-
uws_wrapper =
|
|
23
|
+
uws_wrapper = await import(import.meta.resolve("../uws-wrapper.node"));
|
|
22
24
|
}
|
|
23
|
-
catch (
|
|
24
|
-
uws_wrapper =
|
|
25
|
+
catch (e) {
|
|
26
|
+
uws_wrapper = await import(import.meta.resolve(`../build/Release/uws-wrapper-${os.arch()}.node`));
|
|
27
|
+
}
|
|
28
|
+
if (uws_wrapper) {
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
uws_wrapper = uws_wrapper.default ?? uws_wrapper;
|
|
25
31
|
}
|
|
26
32
|
}
|
|
27
33
|
export default uws_wrapper;
|