@vercel/node 1.13.0 → 1.13.1-canary.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/dist/dev-server.js +4 -2
- package/dist/index.d.ts +5 -7
- package/dist/index.js +14 -60
- package/package.json +4 -5
- package/dist/bridge.js +0 -242
- package/dist/example-import.d.ts +0 -1
- package/dist/helpers.d.ts +0 -10
- package/dist/helpers.js +0 -906
- package/dist/launcher.js +0 -199
- package/dist/source-map-support.js +0 -3959
package/dist/dev-server.js
CHANGED
|
@@ -76,8 +76,7 @@ if (!process.env.VERCEL_DEV_IS_ESM) {
|
|
|
76
76
|
useRequire = true;
|
|
77
77
|
}
|
|
78
78
|
const http_1 = require("http");
|
|
79
|
-
|
|
80
|
-
const launcher_js_1 = require("./launcher.js");
|
|
79
|
+
const launcher_js_1 = require("@vercel/node-bridge/launcher.js");
|
|
81
80
|
function listen(server, port, host) {
|
|
82
81
|
return new Promise(resolve => {
|
|
83
82
|
server.listen(port, host, () => {
|
|
@@ -99,6 +98,9 @@ async function main() {
|
|
|
99
98
|
helpersPath: './helpers.js',
|
|
100
99
|
shouldAddHelpers,
|
|
101
100
|
useRequire,
|
|
101
|
+
// not used
|
|
102
|
+
bridgePath: '',
|
|
103
|
+
sourcemapSupportPath: '',
|
|
102
104
|
});
|
|
103
105
|
bridge = launcher();
|
|
104
106
|
const address = proxyServer.address();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { shouldServe, BuildV3, PrepareCache, StartDevServer } from '@vercel/build-utils';
|
|
2
2
|
export { shouldServe };
|
|
3
|
-
export { NowRequest, NowResponse, VercelRequest, VercelResponse, } from './types';
|
|
3
|
+
export type { NowRequest, NowResponse, VercelRequest, VercelResponse, } from './types';
|
|
4
4
|
export * from './types';
|
|
5
5
|
export declare const version = 3;
|
|
6
|
-
export declare
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export declare function prepareCache({ workPath, }: PrepareCacheOptions): Promise<Files>;
|
|
10
|
-
export declare function startDevServer(opts: StartDevServerOptions): Promise<StartDevServerResult>;
|
|
6
|
+
export declare const build: BuildV3;
|
|
7
|
+
export declare const prepareCache: PrepareCache;
|
|
8
|
+
export declare const startDevServer: StartDevServer;
|
package/dist/index.js
CHANGED
|
@@ -306897,8 +306897,6 @@ const once_1 = __importDefault(__webpack_require__(8478));
|
|
|
306897
306897
|
const nft_1 = __webpack_require__(39582);
|
|
306898
306898
|
const build_utils_1 = __webpack_require__(63445);
|
|
306899
306899
|
Object.defineProperty(exports, "shouldServe", ({ enumerable: true, get: function () { return build_utils_1.shouldServe; } }));
|
|
306900
|
-
// @ts-ignore - copied to the `dist` output as-is
|
|
306901
|
-
const launcher_js_1 = __webpack_require__(59767);
|
|
306902
306900
|
const typescript_1 = __webpack_require__(80774);
|
|
306903
306901
|
function isPortInfo(v) {
|
|
306904
306902
|
return v && typeof v.port === 'number';
|
|
@@ -306907,10 +306905,6 @@ const require_ = eval('require');
|
|
|
306907
306905
|
const tscPath = path_1.resolve(path_1.dirname(require_.resolve('typescript')), '../bin/tsc');
|
|
306908
306906
|
// eslint-disable-next-line no-useless-escape
|
|
306909
306907
|
const libPathRegEx = /^node_modules|[\/\\]node_modules[\/\\]/;
|
|
306910
|
-
const LAUNCHER_FILENAME = '__launcher.js';
|
|
306911
|
-
const BRIDGE_FILENAME = '__bridge.js';
|
|
306912
|
-
const HELPERS_FILENAME = '__helpers.js';
|
|
306913
|
-
const SOURCEMAP_SUPPORT_FILENAME = '__sourcemap_support.js';
|
|
306914
306908
|
async function downloadInstallAndBundle({ files, entrypoint, workPath, config, meta, }) {
|
|
306915
306909
|
const downloadedFiles = await build_utils_1.download(files, workPath, meta);
|
|
306916
306910
|
const entrypointFsDirname = path_1.join(workPath, path_1.dirname(entrypoint));
|
|
@@ -306937,7 +306931,7 @@ function renameTStoJS(path) {
|
|
|
306937
306931
|
}
|
|
306938
306932
|
return path;
|
|
306939
306933
|
}
|
|
306940
|
-
async function compile(workPath, baseDir, entrypointPath,
|
|
306934
|
+
async function compile(workPath, baseDir, entrypointPath, config) {
|
|
306941
306935
|
const inputFiles = new Set([entrypointPath]);
|
|
306942
306936
|
const preparedFiles = {};
|
|
306943
306937
|
const sourceCache = new Map();
|
|
@@ -307021,7 +307015,7 @@ async function compile(workPath, baseDir, entrypointPath, entrypoint, config) {
|
|
|
307021
307015
|
},
|
|
307022
307016
|
});
|
|
307023
307017
|
for (const warning of warnings) {
|
|
307024
|
-
if (warning
|
|
307018
|
+
if (warning === null || warning === void 0 ? void 0 : warning.stack) {
|
|
307025
307019
|
build_utils_1.debug(warning.stack.replace('Error: ', 'Warning: '));
|
|
307026
307020
|
}
|
|
307027
307021
|
}
|
|
@@ -307114,8 +307108,7 @@ function getAWSLambdaHandler(entrypoint, config) {
|
|
|
307114
307108
|
// Ensures that everything from `types.ts` is exported in the final `index.d.ts` file.
|
|
307115
307109
|
__exportStar(__webpack_require__(25748), exports);
|
|
307116
307110
|
exports.version = 3;
|
|
307117
|
-
async
|
|
307118
|
-
const shouldAddHelpers = !(config.helpers === false || process.env.NODEJS_HELPERS === '0');
|
|
307111
|
+
const build = async ({ files, entrypoint, workPath, repoRootPath, config = {}, meta = {}, }) => {
|
|
307119
307112
|
const baseDir = repoRootPath || workPath;
|
|
307120
307113
|
const awsLambdaHandler = getAWSLambdaHandler(entrypoint, config);
|
|
307121
307114
|
const { entrypointPath, entrypointFsDirname, nodeVersion, spawnOpts } = await downloadInstallAndBundle({
|
|
@@ -307130,57 +307123,26 @@ async function build({ files, entrypoint, workPath, repoRootPath, config = {}, m
|
|
|
307130
307123
|
['vercel-build', 'now-build'], spawnOpts);
|
|
307131
307124
|
build_utils_1.debug('Tracing input files...');
|
|
307132
307125
|
const traceTime = Date.now();
|
|
307133
|
-
const { preparedFiles, shouldAddSourcemapSupport } = await compile(workPath, baseDir, entrypointPath,
|
|
307126
|
+
const { preparedFiles, shouldAddSourcemapSupport } = await compile(workPath, baseDir, entrypointPath, config);
|
|
307134
307127
|
build_utils_1.debug(`Trace complete [${Date.now() - traceTime}ms]`);
|
|
307135
|
-
const
|
|
307136
|
-
const
|
|
307137
|
-
|
|
307138
|
-
|
|
307139
|
-
|
|
307140
|
-
helpersPath: `./${HELPERS_FILENAME}`,
|
|
307141
|
-
sourcemapSupportPath: `./${SOURCEMAP_SUPPORT_FILENAME}`,
|
|
307128
|
+
const shouldAddHelpers = !(config.helpers === false || process.env.NODEJS_HELPERS === '0');
|
|
307129
|
+
const lambda = new build_utils_1.NodejsLambda({
|
|
307130
|
+
files: preparedFiles,
|
|
307131
|
+
handler: renameTStoJS(path_1.relative(baseDir, entrypointPath)),
|
|
307132
|
+
runtime: nodeVersion.runtime,
|
|
307142
307133
|
shouldAddHelpers,
|
|
307143
307134
|
shouldAddSourcemapSupport,
|
|
307144
307135
|
awsLambdaHandler,
|
|
307145
307136
|
});
|
|
307146
|
-
const launcherFiles = {
|
|
307147
|
-
[getFileName('package.json')]: new build_utils_1.FileBlob({
|
|
307148
|
-
data: JSON.stringify({ type: 'commonjs' }),
|
|
307149
|
-
}),
|
|
307150
|
-
[getFileName(LAUNCHER_FILENAME)]: new build_utils_1.FileBlob({
|
|
307151
|
-
data: launcherSource,
|
|
307152
|
-
}),
|
|
307153
|
-
[getFileName(BRIDGE_FILENAME)]: new build_utils_1.FileFsRef({
|
|
307154
|
-
fsPath: path_1.join(__dirname, 'bridge.js'),
|
|
307155
|
-
}),
|
|
307156
|
-
};
|
|
307157
|
-
if (shouldAddSourcemapSupport) {
|
|
307158
|
-
launcherFiles[getFileName(SOURCEMAP_SUPPORT_FILENAME)] = new build_utils_1.FileFsRef({
|
|
307159
|
-
fsPath: path_1.join(__dirname, 'source-map-support.js'),
|
|
307160
|
-
});
|
|
307161
|
-
}
|
|
307162
|
-
if (shouldAddHelpers) {
|
|
307163
|
-
launcherFiles[getFileName(HELPERS_FILENAME)] = new build_utils_1.FileFsRef({
|
|
307164
|
-
fsPath: path_1.join(__dirname, 'helpers.js'),
|
|
307165
|
-
});
|
|
307166
|
-
}
|
|
307167
|
-
const lambda = await build_utils_1.createLambda({
|
|
307168
|
-
files: {
|
|
307169
|
-
...preparedFiles,
|
|
307170
|
-
...launcherFiles,
|
|
307171
|
-
},
|
|
307172
|
-
handler: `${getFileName(LAUNCHER_FILENAME).slice(0, -3)}.launcher`,
|
|
307173
|
-
runtime: nodeVersion.runtime,
|
|
307174
|
-
});
|
|
307175
307137
|
return { output: lambda };
|
|
307176
|
-
}
|
|
307138
|
+
};
|
|
307177
307139
|
exports.build = build;
|
|
307178
|
-
async
|
|
307140
|
+
const prepareCache = async ({ workPath }) => {
|
|
307179
307141
|
const cache = await build_utils_1.glob('node_modules/**', workPath);
|
|
307180
307142
|
return cache;
|
|
307181
|
-
}
|
|
307143
|
+
};
|
|
307182
307144
|
exports.prepareCache = prepareCache;
|
|
307183
|
-
async
|
|
307145
|
+
const startDevServer = async (opts) => {
|
|
307184
307146
|
const { entrypoint, workPath, config, meta = {} } = opts;
|
|
307185
307147
|
const entryDir = path_1.join(workPath, path_1.dirname(entrypoint));
|
|
307186
307148
|
const projectTsConfig = await build_utils_1.walkParentDirs({
|
|
@@ -307234,7 +307196,7 @@ async function startDevServer(opts) {
|
|
|
307234
307196
|
const reason = signal ? `"${signal}" signal` : `exit code ${exitCode}`;
|
|
307235
307197
|
throw new Error(`\`node ${entrypoint}\` failed with ${reason}`);
|
|
307236
307198
|
}
|
|
307237
|
-
}
|
|
307199
|
+
};
|
|
307238
307200
|
exports.startDevServer = startDevServer;
|
|
307239
307201
|
async function doTypeCheck({ entrypoint, workPath, meta = {} }, projectTsConfig) {
|
|
307240
307202
|
const { devCacheDir = path_1.join(workPath, '.now', 'cache') } = meta;
|
|
@@ -307640,14 +307602,6 @@ function filterDiagnostics(diagnostics, ignore) {
|
|
|
307640
307602
|
}
|
|
307641
307603
|
|
|
307642
307604
|
|
|
307643
|
-
/***/ }),
|
|
307644
|
-
|
|
307645
|
-
/***/ 59767:
|
|
307646
|
-
/***/ ((module) => {
|
|
307647
|
-
|
|
307648
|
-
module.exports = eval("require")("./launcher.js");
|
|
307649
|
-
|
|
307650
|
-
|
|
307651
307605
|
/***/ }),
|
|
307652
307606
|
|
|
307653
307607
|
/***/ 80918:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/node",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.1-canary.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index",
|
|
6
6
|
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/node-js",
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "node build",
|
|
14
|
-
"test-unit": "jest --env node --verbose --runInBand --bail test/helpers.test.js",
|
|
15
14
|
"test-integration-once": "jest --env node --verbose --runInBand --bail test/integration.test.js",
|
|
16
15
|
"prepublishOnly": "node build"
|
|
17
16
|
},
|
|
@@ -32,10 +31,10 @@
|
|
|
32
31
|
"@types/cookie": "0.3.3",
|
|
33
32
|
"@types/etag": "1.8.0",
|
|
34
33
|
"@types/test-listen": "1.1.0",
|
|
35
|
-
"@vercel/build-utils": "2.14.
|
|
34
|
+
"@vercel/build-utils": "2.14.1-canary.2",
|
|
36
35
|
"@vercel/ncc": "0.24.0",
|
|
37
36
|
"@vercel/nft": "0.17.5",
|
|
38
|
-
"@vercel/node-bridge": "2.1.
|
|
37
|
+
"@vercel/node-bridge": "2.1.2-canary.0",
|
|
39
38
|
"content-type": "1.0.4",
|
|
40
39
|
"cookie": "0.4.0",
|
|
41
40
|
"etag": "1.8.1",
|
|
@@ -44,5 +43,5 @@
|
|
|
44
43
|
"source-map-support": "0.5.12",
|
|
45
44
|
"test-listen": "1.1.0"
|
|
46
45
|
},
|
|
47
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "82ba9324471e7bf3f4426793c86694fdeb4530a4"
|
|
48
47
|
}
|
package/dist/bridge.js
DELETED
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
const { request } = require('http');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* If the `http.Server` handler function throws an error asynchronously,
|
|
5
|
-
* then it ends up being an unhandled rejection which doesn't kill the node
|
|
6
|
-
* process which causes the HTTP request to hang indefinitely. So print the
|
|
7
|
-
* error here and force the process to exit so that the lambda invocation
|
|
8
|
-
* returns an Unhandled error quickly.
|
|
9
|
-
*/
|
|
10
|
-
process.on('unhandledRejection', err => {
|
|
11
|
-
console.error('Unhandled rejection:', err);
|
|
12
|
-
process.exit(1);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @param {import('./types').VercelProxyEvent} event
|
|
17
|
-
*/
|
|
18
|
-
function normalizeProxyEvent(event) {
|
|
19
|
-
let bodyBuffer;
|
|
20
|
-
const { method, path, headers, encoding, body } = JSON.parse(event.body);
|
|
21
|
-
|
|
22
|
-
if (body) {
|
|
23
|
-
if (encoding === 'base64') {
|
|
24
|
-
bodyBuffer = Buffer.from(body, encoding);
|
|
25
|
-
} else if (encoding === undefined) {
|
|
26
|
-
bodyBuffer = Buffer.from(body);
|
|
27
|
-
} else {
|
|
28
|
-
throw new Error(`Unsupported encoding: ${encoding}`);
|
|
29
|
-
}
|
|
30
|
-
} else {
|
|
31
|
-
bodyBuffer = Buffer.alloc(0);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return { isApiGateway: false, method, path, headers, body: bodyBuffer };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @param {import('aws-lambda').APIGatewayProxyEvent} event
|
|
39
|
-
*/
|
|
40
|
-
function normalizeAPIGatewayProxyEvent(event) {
|
|
41
|
-
let bodyBuffer;
|
|
42
|
-
const { httpMethod: method, path, headers, body } = event;
|
|
43
|
-
|
|
44
|
-
if (body) {
|
|
45
|
-
if (event.isBase64Encoded) {
|
|
46
|
-
bodyBuffer = Buffer.from(body, 'base64');
|
|
47
|
-
} else {
|
|
48
|
-
bodyBuffer = Buffer.from(body);
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
bodyBuffer = Buffer.alloc(0);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return { isApiGateway: true, method, path, headers, body: bodyBuffer };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @param {import('./types').VercelProxyEvent | import('aws-lambda').APIGatewayProxyEvent} event
|
|
59
|
-
*/
|
|
60
|
-
function normalizeEvent(event) {
|
|
61
|
-
if ('Action' in event) {
|
|
62
|
-
if (event.Action === 'Invoke') {
|
|
63
|
-
return normalizeProxyEvent(event);
|
|
64
|
-
} else {
|
|
65
|
-
throw new Error(`Unexpected event.Action: ${event.Action}`);
|
|
66
|
-
}
|
|
67
|
-
} else {
|
|
68
|
-
return normalizeAPIGatewayProxyEvent(event);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
class Bridge {
|
|
73
|
-
/**
|
|
74
|
-
* @param {import('./types').ServerLike | null} server
|
|
75
|
-
* @param {boolean} shouldStoreEvents
|
|
76
|
-
*/
|
|
77
|
-
constructor(server = null, shouldStoreEvents = false) {
|
|
78
|
-
this.server = server;
|
|
79
|
-
this.shouldStoreEvents = shouldStoreEvents;
|
|
80
|
-
this.launcher = this.launcher.bind(this);
|
|
81
|
-
this.reqIdSeed = 1;
|
|
82
|
-
/**
|
|
83
|
-
* @type {{ [key: string]: import('./types').VercelProxyRequest }}
|
|
84
|
-
*/
|
|
85
|
-
this.events = {};
|
|
86
|
-
|
|
87
|
-
this.listening = new Promise(resolve => {
|
|
88
|
-
this.resolveListening = resolve;
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* @param {import('./types').ServerLike} server
|
|
94
|
-
*/
|
|
95
|
-
setServer(server) {
|
|
96
|
-
this.server = server;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* @param {boolean} shouldStoreEvents
|
|
101
|
-
*/
|
|
102
|
-
setStoreEvents(shouldStoreEvents) {
|
|
103
|
-
this.shouldStoreEvents = shouldStoreEvents;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
listen() {
|
|
107
|
-
const { server, resolveListening } = this;
|
|
108
|
-
if (!server) {
|
|
109
|
-
throw new Error('Server has not been set!');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (typeof server.timeout === 'number' && server.timeout > 0) {
|
|
113
|
-
// Disable timeout (usually 2 minutes until Node 13).
|
|
114
|
-
// Instead, user should assign function `maxDuration`.
|
|
115
|
-
server.timeout = 0;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return server.listen(
|
|
119
|
-
{
|
|
120
|
-
host: '127.0.0.1',
|
|
121
|
-
port: 0,
|
|
122
|
-
},
|
|
123
|
-
function listeningCallback() {
|
|
124
|
-
if (!this || typeof this.address !== 'function') {
|
|
125
|
-
throw new Error(
|
|
126
|
-
'Missing server.address() function on `this` in server.listen()'
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const addr = this.address();
|
|
131
|
-
|
|
132
|
-
if (!addr) {
|
|
133
|
-
throw new Error('`server.address()` returned `null`');
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (typeof addr === 'string') {
|
|
137
|
-
throw new Error(
|
|
138
|
-
`Unexpected string for \`server.address()\`: ${addr}`
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
resolveListening(addr);
|
|
143
|
-
}
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
*
|
|
149
|
-
* @param {import('./types').VercelProxyEvent | import('aws-lambda').APIGatewayProxyEvent} event
|
|
150
|
-
* @param {import('aws-lambda').Context} context
|
|
151
|
-
* @return {Promise<{statusCode: number, headers: import('http').IncomingHttpHeaders, body: string, encoding: 'base64'}>}
|
|
152
|
-
*/
|
|
153
|
-
async launcher(event, context) {
|
|
154
|
-
context.callbackWaitsForEmptyEventLoop = false;
|
|
155
|
-
const { port } = await this.listening;
|
|
156
|
-
|
|
157
|
-
const normalizedEvent = normalizeEvent(event);
|
|
158
|
-
const { isApiGateway, method, headers, body } = normalizedEvent;
|
|
159
|
-
let { path } = normalizedEvent;
|
|
160
|
-
|
|
161
|
-
if (this.shouldStoreEvents) {
|
|
162
|
-
const reqId = `${this.reqIdSeed++}`;
|
|
163
|
-
this.events[reqId] = normalizedEvent;
|
|
164
|
-
headers['x-now-bridge-request-id'] = reqId;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// eslint-disable-next-line consistent-return
|
|
168
|
-
return new Promise((resolve, reject) => {
|
|
169
|
-
// if the path is improperly encoded we need to encode it or
|
|
170
|
-
// http.request will throw an error (related check: https://github.com/nodejs/node/blob/4ece669c6205ec78abfdadfe78869bbb8411463e/lib/_http_client.js#L84)
|
|
171
|
-
if (path && /[^\u0021-\u00ff]/.test(path)) {
|
|
172
|
-
path = encodeURI(path);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const opts = { hostname: '127.0.0.1', port, path, method };
|
|
176
|
-
const req = request(opts, res => {
|
|
177
|
-
const response = res;
|
|
178
|
-
/**
|
|
179
|
-
* @type {Buffer[]}
|
|
180
|
-
*/
|
|
181
|
-
const respBodyChunks = [];
|
|
182
|
-
response.on('data', chunk => respBodyChunks.push(Buffer.from(chunk)));
|
|
183
|
-
response.on('error', reject);
|
|
184
|
-
response.on('end', () => {
|
|
185
|
-
const bodyBuffer = Buffer.concat(respBodyChunks);
|
|
186
|
-
delete response.headers.connection;
|
|
187
|
-
|
|
188
|
-
if (isApiGateway) {
|
|
189
|
-
delete response.headers['content-length'];
|
|
190
|
-
} else if (response.headers['content-length']) {
|
|
191
|
-
response.headers['content-length'] = String(bodyBuffer.length);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
resolve({
|
|
195
|
-
statusCode: response.statusCode || 200,
|
|
196
|
-
headers: response.headers,
|
|
197
|
-
body: bodyBuffer.toString('base64'),
|
|
198
|
-
encoding: 'base64',
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
req.on('error', error => {
|
|
204
|
-
setTimeout(() => {
|
|
205
|
-
// this lets express print the true error of why the connection was closed.
|
|
206
|
-
// it is probably 'Cannot set headers after they are sent to the client'
|
|
207
|
-
reject(error);
|
|
208
|
-
}, 2);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
for (const [name, value] of Object.entries(headers)) {
|
|
212
|
-
if (value === undefined) {
|
|
213
|
-
console.error(
|
|
214
|
-
`Skipping HTTP request header "${name}" because value is undefined`
|
|
215
|
-
);
|
|
216
|
-
continue;
|
|
217
|
-
}
|
|
218
|
-
try {
|
|
219
|
-
req.setHeader(name, value);
|
|
220
|
-
} catch (err) {
|
|
221
|
-
console.error(`Skipping HTTP request header: "${name}: ${value}"`);
|
|
222
|
-
console.error(err.message);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (body) req.write(body);
|
|
227
|
-
req.end();
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* @param {string} reqId
|
|
233
|
-
* @return {import('./types').VercelProxyRequest}
|
|
234
|
-
*/
|
|
235
|
-
consumeEvent(reqId) {
|
|
236
|
-
const event = this.events[reqId];
|
|
237
|
-
delete this.events[reqId];
|
|
238
|
-
return event;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
module.exports = { Bridge };
|
package/dist/example-import.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/helpers.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { VercelRequest, VercelResponse } from './types';
|
|
3
|
-
import { Server } from 'http';
|
|
4
|
-
import type { Bridge } from '@vercel/node-bridge/bridge';
|
|
5
|
-
export declare class ApiError extends Error {
|
|
6
|
-
readonly statusCode: number;
|
|
7
|
-
constructor(statusCode: number, message: string);
|
|
8
|
-
}
|
|
9
|
-
export declare function sendError(res: VercelResponse, statusCode: number, message: string): void;
|
|
10
|
-
export declare function createServerWithHelpers(handler: (req: VercelRequest, res: VercelResponse) => void | Promise<void>, bridge: Bridge): Server;
|