@vercel/node 3.0.8 → 3.0.10
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/dev-server.mjs +22 -56
- package/dist/index.d.ts +2 -1
- package/package.json +3 -3
package/dist/dev-server.mjs
CHANGED
@@ -528,7 +528,7 @@ function createNodeCompatPlugin() {
|
|
528
528
|
|
529
529
|
// src/edge-functions/edge-handler.mts
|
530
530
|
import { EdgeRuntime, runServer } from "edge-runtime";
|
531
|
-
import {
|
531
|
+
import { Headers as Headers2, request as undiciRequest } from "undici";
|
532
532
|
import { isError } from "@vercel/error-utils";
|
533
533
|
import { readFileSync } from "fs";
|
534
534
|
|
@@ -589,6 +589,7 @@ async function serializeBody(request) {
|
|
589
589
|
// src/edge-functions/edge-handler.mts
|
590
590
|
import esbuild from "esbuild";
|
591
591
|
import exitHook from "exit-hook";
|
592
|
+
import { buildToHeaders } from "@edge-runtime/node-utils";
|
592
593
|
import { fileURLToPath } from "url";
|
593
594
|
var NODE_VERSION_MAJOR = process.version.match(/^v(\d+)\.\d+/)?.[1];
|
594
595
|
var NODE_VERSION_IDENTIFIER = `node${NODE_VERSION_MAJOR}`;
|
@@ -597,6 +598,7 @@ if (!NODE_VERSION_MAJOR) {
|
|
597
598
|
`Unable to determine current node version: process.version=${process.version}`
|
598
599
|
);
|
599
600
|
}
|
601
|
+
var toHeaders = buildToHeaders({ Headers: Headers2 });
|
600
602
|
var __dirname = fileURLToPath(new URL(".", import.meta.url));
|
601
603
|
var edgeHandlerTemplate = readFileSync(
|
602
604
|
`${__dirname}/edge-handler-template.js`
|
@@ -724,20 +726,19 @@ async function createEdgeEventHandler(entrypointFullPath, entrypointRelativePath
|
|
724
726
|
if (!server) {
|
725
727
|
process.exit(1);
|
726
728
|
}
|
727
|
-
const headers = new Headers2(request.headers);
|
728
729
|
const body = await serializeBody(request);
|
729
730
|
if (body !== void 0)
|
730
|
-
headers
|
731
|
+
request.headers["content-length"] = String(body.length);
|
731
732
|
const url = new URL(request.url ?? "/", server.url);
|
732
|
-
const response = await
|
733
|
+
const response = await undiciRequest(url, {
|
733
734
|
body,
|
734
|
-
headers,
|
735
|
-
method: request.method
|
736
|
-
redirect: "manual"
|
735
|
+
headers: request.headers,
|
736
|
+
method: request.method || "GET"
|
737
737
|
});
|
738
|
-
const
|
739
|
-
|
740
|
-
|
738
|
+
const resHeaders = toHeaders(response.headers);
|
739
|
+
const isUserError = resHeaders.get("x-vercel-failed") === "edge-wrapper";
|
740
|
+
if (isUserError && response.statusCode >= 500) {
|
741
|
+
const body2 = await response.body.text();
|
741
742
|
const fakeStackTrace = ` at (${entrypointRelativePath})`;
|
742
743
|
const requestPath = entrypointToRequestPath(
|
743
744
|
entrypointRelativePath,
|
@@ -750,8 +751,8 @@ ${fakeStackTrace}`
|
|
750
751
|
process.exit(1);
|
751
752
|
}
|
752
753
|
return {
|
753
|
-
status: response.
|
754
|
-
headers:
|
754
|
+
status: response.statusCode,
|
755
|
+
headers: resHeaders,
|
755
756
|
body: response.body,
|
756
757
|
encoding: "utf8"
|
757
758
|
};
|
@@ -972,11 +973,12 @@ async function addHelpers(_req, _res) {
|
|
972
973
|
// src/serverless-functions/serverless-handler.mts
|
973
974
|
import { createServer } from "http";
|
974
975
|
import exitHook2 from "exit-hook";
|
975
|
-
import { Headers as Headers3,
|
976
|
+
import { Headers as Headers3, request as undiciRequest2 } from "undici";
|
976
977
|
import { listen } from "async-listen";
|
977
978
|
import { isAbsolute } from "path";
|
978
979
|
import { pathToFileURL } from "url";
|
979
|
-
import
|
980
|
+
import { buildToHeaders as buildToHeaders2 } from "@edge-runtime/node-utils";
|
981
|
+
var toHeaders2 = buildToHeaders2({ Headers: Headers3 });
|
980
982
|
var [NODE_MAJOR] = process.versions.node.split(".").map((v) => Number(v));
|
981
983
|
var HTTP_METHODS = [
|
982
984
|
"GET",
|
@@ -987,26 +989,6 @@ var HTTP_METHODS = [
|
|
987
989
|
"DELETE",
|
988
990
|
"PATCH"
|
989
991
|
];
|
990
|
-
function compress(body, encoding) {
|
991
|
-
switch (encoding) {
|
992
|
-
case "br":
|
993
|
-
return zlib.brotliCompressSync(body, {
|
994
|
-
params: {
|
995
|
-
[zlib.constants.BROTLI_PARAM_QUALITY]: 0
|
996
|
-
}
|
997
|
-
});
|
998
|
-
case "gzip":
|
999
|
-
return zlib.gzipSync(body, {
|
1000
|
-
level: zlib.constants.Z_BEST_SPEED
|
1001
|
-
});
|
1002
|
-
case "deflate":
|
1003
|
-
return zlib.deflateSync(body, {
|
1004
|
-
level: zlib.constants.Z_BEST_SPEED
|
1005
|
-
});
|
1006
|
-
default:
|
1007
|
-
throw new Error(`encoding '${encoding}' not supported`);
|
1008
|
-
}
|
1009
|
-
}
|
1010
992
|
async function createServerlessServer(userCode) {
|
1011
993
|
const server = createServer(userCode);
|
1012
994
|
exitHook2(() => server.close());
|
@@ -1040,38 +1022,23 @@ async function createServerlessEventHandler(entrypointPath, options) {
|
|
1040
1022
|
const isStreaming = options.mode === "streaming";
|
1041
1023
|
return async function(request) {
|
1042
1024
|
const url = new URL(request.url ?? "/", server.url);
|
1043
|
-
const response = await
|
1025
|
+
const response = await undiciRequest2(url, {
|
1044
1026
|
body: await serializeBody(request),
|
1045
|
-
compress: !isStreaming,
|
1046
|
-
// @ts-expect-error
|
1047
1027
|
headers: {
|
1048
1028
|
...request.headers,
|
1049
1029
|
host: request.headers["x-forwarded-host"]
|
1050
1030
|
},
|
1051
|
-
method: request.method
|
1052
|
-
redirect: "manual"
|
1031
|
+
method: request.method || "GET"
|
1053
1032
|
});
|
1054
1033
|
let body = null;
|
1055
|
-
let headers = response.headers;
|
1034
|
+
let headers = toHeaders2(response.headers);
|
1056
1035
|
if (isStreaming) {
|
1057
1036
|
body = response.body;
|
1058
1037
|
} else {
|
1059
|
-
body = Buffer.from(await response.arrayBuffer());
|
1060
|
-
const contentEncoding = response.headers.get("content-encoding");
|
1061
|
-
if (contentEncoding) {
|
1062
|
-
body = compress(body, contentEncoding);
|
1063
|
-
const clonedHeaders = [];
|
1064
|
-
for (const [key, value] of response.headers.entries()) {
|
1065
|
-
if (key !== "transfer-encoding") {
|
1066
|
-
clonedHeaders.push([key, value]);
|
1067
|
-
}
|
1068
|
-
}
|
1069
|
-
clonedHeaders.push(["content-length", String(Buffer.byteLength(body))]);
|
1070
|
-
headers = new Headers3(clonedHeaders);
|
1071
|
-
}
|
1038
|
+
body = Buffer.from(await response.body.arrayBuffer());
|
1072
1039
|
}
|
1073
1040
|
return {
|
1074
|
-
status: response.
|
1041
|
+
status: response.statusCode,
|
1075
1042
|
headers,
|
1076
1043
|
body,
|
1077
1044
|
encoding: "utf8"
|
@@ -1080,7 +1047,6 @@ async function createServerlessEventHandler(entrypointPath, options) {
|
|
1080
1047
|
}
|
1081
1048
|
|
1082
1049
|
// src/dev-server.mts
|
1083
|
-
import { toToReadable } from "@edge-runtime/node-utils";
|
1084
1050
|
import { getConfig } from "@vercel/static-config";
|
1085
1051
|
import { Project } from "ts-morph";
|
1086
1052
|
import { listen as listen2 } from "async-listen";
|
@@ -1157,7 +1123,7 @@ async function onDevRequest(req, res) {
|
|
1157
1123
|
} else if (body instanceof Buffer) {
|
1158
1124
|
res.end(body);
|
1159
1125
|
} else {
|
1160
|
-
|
1126
|
+
body.pipe(res);
|
1161
1127
|
}
|
1162
1128
|
} catch (error) {
|
1163
1129
|
res.statusCode = 500;
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { ServerResponse, IncomingMessage } from 'http';
|
2
2
|
import type { Headers } from 'undici';
|
3
|
+
import type { Readable } from 'stream';
|
3
4
|
|
4
5
|
export type VercelRequestCookies = { [key: string]: string };
|
5
6
|
export type VercelRequestQuery = { [key: string]: string | string[] };
|
@@ -44,6 +45,6 @@ export type NowApiHandler = VercelApiHandler;
|
|
44
45
|
export interface VercelProxyResponse {
|
45
46
|
status: number;
|
46
47
|
headers: Headers;
|
47
|
-
body:
|
48
|
+
body: Readable | Buffer | null;
|
48
49
|
encoding: BufferEncoding;
|
49
50
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vercel/node",
|
3
|
-
"version": "3.0.
|
3
|
+
"version": "3.0.10",
|
4
4
|
"license": "Apache-2.0",
|
5
5
|
"main": "./dist/index",
|
6
6
|
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/node-js",
|
@@ -17,7 +17,7 @@
|
|
17
17
|
"@edge-runtime/primitives": "4.0.5",
|
18
18
|
"@edge-runtime/vm": "3.1.7",
|
19
19
|
"@types/node": "14.18.33",
|
20
|
-
"@vercel/build-utils": "7.2.
|
20
|
+
"@vercel/build-utils": "7.2.4",
|
21
21
|
"@vercel/error-utils": "2.0.2",
|
22
22
|
"@vercel/nft": "0.24.2",
|
23
23
|
"@vercel/static-config": "3.0.0",
|
@@ -31,7 +31,7 @@
|
|
31
31
|
"ts-morph": "12.0.0",
|
32
32
|
"ts-node": "10.9.1",
|
33
33
|
"typescript": "4.9.5",
|
34
|
-
"undici": "5.
|
34
|
+
"undici": "5.26.5"
|
35
35
|
},
|
36
36
|
"devDependencies": {
|
37
37
|
"@babel/core": "7.5.0",
|