srvx 0.1.0 → 0.1.1
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
CHANGED
|
@@ -11,7 +11,7 @@ Universal Server API based on web platform standards. Works with [Deno](https://
|
|
|
11
11
|
|
|
12
12
|
- ✅ Seamless runtime integration with identical usage ([handler](https://srvx.unjs.io/guide/handler) and
|
|
13
13
|
- ✅ Zero overhead [Deno](https://deno.com/) and [Bun](https://bun.sh/) support
|
|
14
|
-
- ✅ [Node.js compatibility](https://srvx.unjs.io/guide/node) with ~native perf and [fast response]https://srvx.unjs.io/guide/node#fast-response) support
|
|
14
|
+
- ✅ [Node.js compatibility](https://srvx.unjs.io/guide/node) with ~native perf and [fast response](https://srvx.unjs.io/guide/node#fast-response) support
|
|
15
15
|
|
|
16
16
|
## Quick start
|
|
17
17
|
|
|
@@ -24,15 +24,15 @@ declare const NodeRequestProxy: {
|
|
|
24
24
|
req: NodeHttp__default.IncomingMessage;
|
|
25
25
|
res: NodeHttp__default.ServerResponse;
|
|
26
26
|
} | undefined;
|
|
27
|
-
"__#
|
|
28
|
-
"__#
|
|
29
|
-
"__#
|
|
30
|
-
"__#
|
|
31
|
-
"__#
|
|
32
|
-
"__#
|
|
33
|
-
"__#
|
|
34
|
-
"__#
|
|
35
|
-
"__#
|
|
27
|
+
"__#3@#url": URL;
|
|
28
|
+
"__#3@#abortSignal"?: AbortController;
|
|
29
|
+
"__#3@#hasBody": boolean | undefined;
|
|
30
|
+
"__#3@#rawBody"?: Promise<Uint8Array>;
|
|
31
|
+
"__#3@#blobBody"?: Promise<Blob>;
|
|
32
|
+
"__#3@#formDataBody"?: Promise<FormData>;
|
|
33
|
+
"__#3@#jsonBody"?: Promise<any>;
|
|
34
|
+
"__#3@#textBody"?: Promise<string>;
|
|
35
|
+
"__#3@#bodyStream"?: undefined | ReadableStream<Uint8Array>;
|
|
36
36
|
readonly xRemoteAddress: string | undefined;
|
|
37
37
|
clone(): xRequest;
|
|
38
38
|
readonly url: string;
|
|
@@ -58,8 +58,8 @@ declare const NodeRequestProxy: {
|
|
|
58
58
|
type NodeFastResponse = InstanceType<typeof NodeFastResponse>;
|
|
59
59
|
declare const NodeFastResponse: {
|
|
60
60
|
new (body?: BodyInit | null, init?: ResponseInit): {
|
|
61
|
-
"__#
|
|
62
|
-
"__#
|
|
61
|
+
"__#4@#body"?: BodyInit | null;
|
|
62
|
+
"__#4@#init"?: ResponseInit;
|
|
63
63
|
/**
|
|
64
64
|
* Prepare Node.js response object
|
|
65
65
|
*/
|
|
@@ -70,11 +70,11 @@ declare const NodeFastResponse: {
|
|
|
70
70
|
body: string | Uint8Array | ReadableStream<Uint8Array> | Buffer | DataView | null | undefined;
|
|
71
71
|
};
|
|
72
72
|
/** Lazy initialized response instance */
|
|
73
|
-
"__#
|
|
73
|
+
"__#4@#responseObj"?: Response;
|
|
74
74
|
/** Lazy initialized headers instance */
|
|
75
|
-
"__#
|
|
75
|
+
"__#4@#headersObj"?: Headers;
|
|
76
76
|
clone(): Response;
|
|
77
|
-
readonly "__#
|
|
77
|
+
readonly "__#4@#response": Response;
|
|
78
78
|
readonly headers: Headers;
|
|
79
79
|
readonly ok: boolean;
|
|
80
80
|
readonly redirected: boolean;
|
|
@@ -82,7 +82,7 @@ declare const NodeFastResponse: {
|
|
|
82
82
|
readonly statusText: string;
|
|
83
83
|
readonly type: ResponseType;
|
|
84
84
|
readonly url: string;
|
|
85
|
-
"__#
|
|
85
|
+
"__#4@#fastBody"<T extends object>(as: new (...args: any[]) => T): T | null | false;
|
|
86
86
|
readonly body: ReadableStream<Uint8Array> | null;
|
|
87
87
|
readonly bodyUsed: boolean;
|
|
88
88
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
@@ -24,15 +24,15 @@ declare const NodeRequestProxy: {
|
|
|
24
24
|
req: NodeHttp__default.IncomingMessage;
|
|
25
25
|
res: NodeHttp__default.ServerResponse;
|
|
26
26
|
} | undefined;
|
|
27
|
-
"__#
|
|
28
|
-
"__#
|
|
29
|
-
"__#
|
|
30
|
-
"__#
|
|
31
|
-
"__#
|
|
32
|
-
"__#
|
|
33
|
-
"__#
|
|
34
|
-
"__#
|
|
35
|
-
"__#
|
|
27
|
+
"__#3@#url": URL;
|
|
28
|
+
"__#3@#abortSignal"?: AbortController;
|
|
29
|
+
"__#3@#hasBody": boolean | undefined;
|
|
30
|
+
"__#3@#rawBody"?: Promise<Uint8Array>;
|
|
31
|
+
"__#3@#blobBody"?: Promise<Blob>;
|
|
32
|
+
"__#3@#formDataBody"?: Promise<FormData>;
|
|
33
|
+
"__#3@#jsonBody"?: Promise<any>;
|
|
34
|
+
"__#3@#textBody"?: Promise<string>;
|
|
35
|
+
"__#3@#bodyStream"?: undefined | ReadableStream<Uint8Array>;
|
|
36
36
|
readonly xRemoteAddress: string | undefined;
|
|
37
37
|
clone(): xRequest;
|
|
38
38
|
readonly url: string;
|
|
@@ -58,8 +58,8 @@ declare const NodeRequestProxy: {
|
|
|
58
58
|
type NodeFastResponse = InstanceType<typeof NodeFastResponse>;
|
|
59
59
|
declare const NodeFastResponse: {
|
|
60
60
|
new (body?: BodyInit | null, init?: ResponseInit): {
|
|
61
|
-
"__#
|
|
62
|
-
"__#
|
|
61
|
+
"__#4@#body"?: BodyInit | null;
|
|
62
|
+
"__#4@#init"?: ResponseInit;
|
|
63
63
|
/**
|
|
64
64
|
* Prepare Node.js response object
|
|
65
65
|
*/
|
|
@@ -70,11 +70,11 @@ declare const NodeFastResponse: {
|
|
|
70
70
|
body: string | Uint8Array | ReadableStream<Uint8Array> | Buffer | DataView | null | undefined;
|
|
71
71
|
};
|
|
72
72
|
/** Lazy initialized response instance */
|
|
73
|
-
"__#
|
|
73
|
+
"__#4@#responseObj"?: Response;
|
|
74
74
|
/** Lazy initialized headers instance */
|
|
75
|
-
"__#
|
|
75
|
+
"__#4@#headersObj"?: Headers;
|
|
76
76
|
clone(): Response;
|
|
77
|
-
readonly "__#
|
|
77
|
+
readonly "__#4@#response": Response;
|
|
78
78
|
readonly headers: Headers;
|
|
79
79
|
readonly ok: boolean;
|
|
80
80
|
readonly redirected: boolean;
|
|
@@ -82,7 +82,7 @@ declare const NodeFastResponse: {
|
|
|
82
82
|
readonly statusText: string;
|
|
83
83
|
readonly type: ResponseType;
|
|
84
84
|
readonly url: string;
|
|
85
|
-
"__#
|
|
85
|
+
"__#4@#fastBody"<T extends object>(as: new (...args: any[]) => T): T | null | false;
|
|
86
86
|
readonly body: ReadableStream<Uint8Array> | null;
|
|
87
87
|
readonly bodyUsed: boolean;
|
|
88
88
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a as NodeReqHeadersProxy, N as NodeRequestProxy, b as NodeResHeadersProxy, s as sendNodeResponse } from '../shared/srvx.
|
|
1
|
+
export { a as NodeReqHeadersProxy, N as NodeRequestProxy, b as NodeResHeadersProxy, s as sendNodeResponse } from '../shared/srvx.109e963a.mjs';
|
|
2
2
|
import { splitSetCookieString } from 'cookie-es';
|
|
3
3
|
|
|
4
4
|
const NodeFastResponse = /* @__PURE__ */ (() => (
|
package/dist/node.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import NodeHttp from 'node:http';
|
|
2
2
|
import { S as Server, r as resolvePort } from './shared/srvx.4f681732.mjs';
|
|
3
|
-
import { N as NodeRequestProxy, s as sendNodeResponse } from './shared/srvx.
|
|
3
|
+
import { N as NodeRequestProxy, s as sendNodeResponse } from './shared/srvx.109e963a.mjs';
|
|
4
4
|
import 'cookie-es';
|
|
5
5
|
|
|
6
6
|
function serve(options) {
|
|
@@ -480,7 +480,13 @@ async function sendNodeResponse(nodeRes, webRes) {
|
|
|
480
480
|
if (webRes.xNodeResponse) {
|
|
481
481
|
const res = webRes.xNodeResponse();
|
|
482
482
|
nodeRes.writeHead(res.status, res.statusText, res.headers);
|
|
483
|
-
|
|
483
|
+
if (res.body instanceof ReadableStream) {
|
|
484
|
+
return streamBody(res.body, nodeRes).finally(
|
|
485
|
+
() => endNodeResponse(nodeRes)
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
nodeRes.write(res.body);
|
|
489
|
+
return endNodeResponse(nodeRes);
|
|
484
490
|
}
|
|
485
491
|
const headerEntries = [];
|
|
486
492
|
for (const [key, value] of webRes.headers) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "srvx",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Universal Server API based on web platform standards. Works seamlessly with Deno, Bun and Node.js.",
|
|
5
5
|
"repository": "unjs/srvx",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,9 +33,6 @@
|
|
|
33
33
|
"lint": "eslint . && prettier -c .",
|
|
34
34
|
"lint:fix": "automd && eslint . --fix && prettier -w .",
|
|
35
35
|
"prepack": "pnpm build",
|
|
36
|
-
"play:bun": "bun run ./playground/index.ts",
|
|
37
|
-
"play:deno": "deno run --unstable-byonm -A ./playground/index.ts",
|
|
38
|
-
"play:node": "node --import jiti/register ./playground/index.ts",
|
|
39
36
|
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
|
|
40
37
|
"test": "pnpm lint && pnpm test:types && vitest run --coverage",
|
|
41
38
|
"test:types": "tsc --noEmit --skipLibCheck"
|