@morojs/moro 1.8.6 → 1.8.8
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/dist/core/http/http-server.d.ts +5 -3
- package/dist/core/http/http-server.js +42 -11
- package/dist/core/http/http-server.js.map +1 -1
- package/dist/core/http/http2-server.d.ts +1 -1
- package/dist/core/http/http2-server.js +27 -9
- package/dist/core/http/http2-server.js.map +1 -1
- package/dist/core/http/moro-engine-server.d.ts +24 -4
- package/dist/core/http/moro-engine-server.js +198 -42
- package/dist/core/http/moro-engine-server.js.map +1 -1
- package/dist/core/http/uws-http-server.js +4 -0
- package/dist/core/http/uws-http-server.js.map +1 -1
- package/dist/core/middleware/built-in/cookie/core.d.ts +26 -1
- package/dist/core/middleware/built-in/cookie/core.js +70 -2
- package/dist/core/middleware/built-in/cookie/core.js.map +1 -1
- package/dist/core/middleware/built-in/cookie/hook.d.ts +3 -1
- package/dist/core/middleware/built-in/cookie/hook.js +17 -5
- package/dist/core/middleware/built-in/cookie/hook.js.map +1 -1
- package/dist/core/middleware/built-in/cookie/index.d.ts +1 -1
- package/dist/core/middleware/built-in/cookie/index.js +1 -1
- package/dist/core/middleware/built-in/cookie/index.js.map +1 -1
- package/dist/core/middleware/built-in/cookie/middleware.d.ts +1 -1
- package/dist/core/middleware/built-in/cookie/middleware.js +6 -4
- package/dist/core/middleware/built-in/cookie/middleware.js.map +1 -1
- package/dist/core/middleware/built-in/index.d.ts +4 -12
- package/dist/core/middleware/built-in/rate-limit/core.d.ts +24 -0
- package/dist/core/middleware/built-in/rate-limit/core.js +47 -0
- package/dist/core/middleware/built-in/rate-limit/core.js.map +1 -1
- package/dist/core/middleware/built-in/rate-limit/hook.d.ts +24 -9
- package/dist/core/middleware/built-in/rate-limit/hook.js +34 -12
- package/dist/core/middleware/built-in/rate-limit/hook.js.map +1 -1
- package/dist/core/middleware/built-in/rate-limit/middleware.js +9 -1
- package/dist/core/middleware/built-in/rate-limit/middleware.js.map +1 -1
- package/dist/core/middleware/built-in/session/core.d.ts +8 -0
- package/dist/core/middleware/built-in/session/core.js +29 -2
- package/dist/core/middleware/built-in/session/core.js.map +1 -1
- package/dist/core/middleware/built-in/session/hook.js +2 -3
- package/dist/core/middleware/built-in/session/hook.js.map +1 -1
- package/dist/core/middleware/built-in/session/middleware.js +2 -3
- package/dist/core/middleware/built-in/session/middleware.js.map +1 -1
- package/dist/core/middleware/built-in/static/core.d.ts +56 -0
- package/dist/core/middleware/built-in/static/core.js +214 -13
- package/dist/core/middleware/built-in/static/core.js.map +1 -1
- package/dist/core/middleware/built-in/static/middleware.d.ts +5 -0
- package/dist/core/middleware/built-in/static/middleware.js +5 -0
- package/dist/core/middleware/built-in/static/middleware.js.map +1 -1
- package/dist/core/middleware/built-in/upload/core.d.ts +17 -0
- package/dist/core/middleware/built-in/upload/core.js +30 -1
- package/dist/core/middleware/built-in/upload/core.js.map +1 -1
- package/dist/core/middleware/built-in/upload/middleware.js +12 -1
- package/dist/core/middleware/built-in/upload/middleware.js.map +1 -1
- package/dist/core/pooling/object-pool-manager.js +14 -20
- package/dist/core/pooling/object-pool-manager.js.map +1 -1
- package/dist/core/routing/index.d.ts +1 -0
- package/dist/core/routing/index.js.map +1 -1
- package/dist/core/routing/radix-tree.d.ts +1 -0
- package/dist/core/routing/radix-tree.js +6 -1
- package/dist/core/routing/radix-tree.js.map +1 -1
- package/dist/core/routing/unified-router.js +28 -25
- package/dist/core/routing/unified-router.js.map +1 -1
- package/dist/core/utilities/hooks.d.ts +2 -0
- package/dist/core/utilities/hooks.js +28 -2
- package/dist/core/utilities/hooks.js.map +1 -1
- package/dist/index.d.ts +2 -6
- package/dist/moro.js +12 -0
- package/dist/moro.js.map +1 -1
- package/dist/types/http.d.ts +3 -0
- package/dist/types/http.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Server } from 'http';
|
|
2
2
|
import type { HttpRuntimeLimits } from './utils/size.js';
|
|
3
3
|
import { HttpRequest, HttpResponse, HttpHandler, Middleware } from '../../types/http.js';
|
|
4
|
-
|
|
4
|
+
declare const http: typeof import("http");
|
|
5
|
+
export declare class MoroIncomingMessage extends http.IncomingMessage {
|
|
5
6
|
/** Bound on the per-server subclass prototype - no per-request write needed */
|
|
6
7
|
_server: MoroHttpServer;
|
|
7
8
|
params: Record<string, string>;
|
|
@@ -39,7 +40,7 @@ export declare class MoroIncomingMessage extends IncomingMessage {
|
|
|
39
40
|
accepts(types?: string | string[]): string | false;
|
|
40
41
|
acceptsLanguages(langs?: string | string[]): string | false;
|
|
41
42
|
}
|
|
42
|
-
export declare class MoroServerResponse extends ServerResponse {
|
|
43
|
+
export declare class MoroServerResponse extends http.ServerResponse {
|
|
43
44
|
/** Bound on the per-server subclass prototype - no per-request write needed */
|
|
44
45
|
_server: MoroHttpServer;
|
|
45
46
|
_locals: Record<string, any> | undefined;
|
|
@@ -256,3 +257,4 @@ export declare class MoroHttpServer {
|
|
|
256
257
|
};
|
|
257
258
|
};
|
|
258
259
|
}
|
|
260
|
+
export {};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { IncomingMessage, ServerResponse, createServer } from 'http';
|
|
3
|
-
import { createServer as createHttpsServer } from 'https';
|
|
4
|
-
import * as zlib from 'zlib';
|
|
1
|
+
import { createRequire } from 'module';
|
|
5
2
|
import { promisify } from 'util';
|
|
6
3
|
import { randomUUID } from 'crypto';
|
|
7
4
|
import { createFrameworkLogger } from '../logger/index.js';
|
|
@@ -9,8 +6,35 @@ import { parseMultipart as parseMultipartBuffer, } from './utils/multipart-parse
|
|
|
9
6
|
import { parseRawQueryString } from './utils/query-parser.js';
|
|
10
7
|
import { PathMatcher } from '../routing/path-matcher.js';
|
|
11
8
|
import { ObjectPoolManager } from '../pooling/object-pool-manager.js';
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
// `node:https` and `node:zlib` are resolved on first use rather than at import
|
|
10
|
+
// time. This module is on every app's startup path, but plaintext HTTP apps
|
|
11
|
+
// never touch https (~1.9 MB RSS, it drags in tls) and uncompressed responses
|
|
12
|
+
// never touch zlib (~0.3 MB). Builtins are always synchronously requirable, so
|
|
13
|
+
// the secure-server and compression paths stay fully synchronous.
|
|
14
|
+
// Resolves Node builtins ONLY, so the base passed to createRequire is
|
|
15
|
+
// irrelevant - 'file:///' is used instead of import.meta.url so this file still
|
|
16
|
+
// compiles under the CJS transform Jest applies to the test suite.
|
|
17
|
+
const requireBuiltin = createRequire('file:///');
|
|
18
|
+
// `node:http` is pulled through createRequire rather than `import`. In an ESM
|
|
19
|
+
// package the two are NOT equivalent: building the ESM facade for node:http
|
|
20
|
+
// drags in http2, tls, zlib and worker_threads and costs ~10.4 MB RSS, while
|
|
21
|
+
// require('http') costs ~0.9 MB and pulls only net. Same objects, same
|
|
22
|
+
// semantics - measurably less memory. See also the lazy https/zlib below.
|
|
23
|
+
const http = requireBuiltin('http');
|
|
24
|
+
const createServer = http.createServer;
|
|
25
|
+
let gzipFn;
|
|
26
|
+
let deflateFn;
|
|
27
|
+
function compressors() {
|
|
28
|
+
if (!gzipFn) {
|
|
29
|
+
const zlib = requireBuiltin('zlib');
|
|
30
|
+
gzipFn = promisify(zlib.gzip);
|
|
31
|
+
deflateFn = promisify(zlib.deflate);
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
gzip: gzipFn,
|
|
35
|
+
deflate: deflateFn,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
14
38
|
const JSON_CONTENT_TYPE = 'application/json; charset=utf-8';
|
|
15
39
|
const STATUS_MESSAGES = {
|
|
16
40
|
200: 'OK',
|
|
@@ -83,7 +107,7 @@ function parseCookieHeader(cookieHeader) {
|
|
|
83
107
|
// the `_server` back-reference, so methods can reach server config (logger,
|
|
84
108
|
// compression settings) without any per-request allocation.
|
|
85
109
|
// ---------------------------------------------------------------------------
|
|
86
|
-
export class MoroIncomingMessage extends IncomingMessage {
|
|
110
|
+
export class MoroIncomingMessage extends http.IncomingMessage {
|
|
87
111
|
// Hot per-request fields (assigned in handleRequest; declared here for
|
|
88
112
|
// stable shape). Everything else lives behind the single `_lazy` slot -
|
|
89
113
|
// per-request construction pays 5 field initializations instead of 16.
|
|
@@ -327,7 +351,7 @@ export class MoroIncomingMessage extends IncomingMessage {
|
|
|
327
351
|
return false;
|
|
328
352
|
}
|
|
329
353
|
}
|
|
330
|
-
export class MoroServerResponse extends ServerResponse {
|
|
354
|
+
export class MoroServerResponse extends http.ServerResponse {
|
|
331
355
|
_locals = undefined;
|
|
332
356
|
get locals() {
|
|
333
357
|
let l = this._locals;
|
|
@@ -354,7 +378,8 @@ export class MoroServerResponse extends ServerResponse {
|
|
|
354
378
|
const acceptEncoding = this.req?.headers['accept-encoding'];
|
|
355
379
|
if (acceptEncoding && acceptEncoding.includes('gzip')) {
|
|
356
380
|
const buffer = Buffer.from(jsonString, 'utf8');
|
|
357
|
-
|
|
381
|
+
compressors()
|
|
382
|
+
.gzip(buffer)
|
|
358
383
|
.then(compressed => {
|
|
359
384
|
if (this.headersSent)
|
|
360
385
|
return;
|
|
@@ -385,7 +410,8 @@ export class MoroServerResponse extends ServerResponse {
|
|
|
385
410
|
}
|
|
386
411
|
else if (acceptEncoding && acceptEncoding.includes('deflate')) {
|
|
387
412
|
const buffer = Buffer.from(jsonString, 'utf8');
|
|
388
|
-
|
|
413
|
+
compressors()
|
|
414
|
+
.deflate(buffer)
|
|
389
415
|
.then(compressed => {
|
|
390
416
|
if (this.headersSent)
|
|
391
417
|
return;
|
|
@@ -935,7 +961,8 @@ export class MoroHttpServer {
|
|
|
935
961
|
if (options?.ssl) {
|
|
936
962
|
// In-process HTTPS. The https ServerOptions extends the http one, so the
|
|
937
963
|
// IncomingMessage/ServerResponse subclass injection carries over.
|
|
938
|
-
|
|
964
|
+
const https = requireBuiltin('https');
|
|
965
|
+
this.server = https.createServer({ ...serverOpts, ...options.ssl }, this.handleRequest.bind(this));
|
|
939
966
|
this.logger.info('HTTPS server created (in-process TLS)', 'HttpServer');
|
|
940
967
|
}
|
|
941
968
|
else {
|
|
@@ -1201,6 +1228,10 @@ export class MoroHttpServer {
|
|
|
1201
1228
|
});
|
|
1202
1229
|
}
|
|
1203
1230
|
}
|
|
1231
|
+
// A request hook may answer the request itself (rate limiting, auth
|
|
1232
|
+
// rejection). Registration of the response hooks above still stands.
|
|
1233
|
+
if (httpRes.headersSent)
|
|
1234
|
+
return;
|
|
1204
1235
|
// executeMiddleware returns undefined when the whole chain completed
|
|
1205
1236
|
// synchronously, so a sync chain costs zero promise allocations.
|
|
1206
1237
|
if (this.globalMiddleware.length > 0) {
|