const { AWS_LAMBDA_RUNTIME_API, LAMBDA_TASK_ROOT, _HANDLER } = process.env; if (!AWS_LAMBDA_RUNTIME_API || AWS_LAMBDA_RUNTIME_API === "") { throw new Error("AWS_LAMBDA_RUNTIME_API is not set"); } const nextURL = `http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/next`; const sourceDir = LAMBDA_TASK_ROOT; if (!sourceDir) { throw new Error("handler is not set"); } // don't care if this fails if (process.cwd() !== sourceDir) { try { process.chdir(sourceDir); } catch (e) {} } var handlerDot = _HANDLER.lastIndexOf("."); var sourcefile = handlerDot > 0 ? _HANDLER.substring(0, handlerDot) : _HANDLER; if (sourcefile.length === 0) { throw new Error("handler is not set"); } if (!sourcefile.startsWith("/")) { sourcefile = `./${sourcefile}`; } function noop() {} const method = (handlerDot > 0 ? _HANDLER.substring(handlerDot) : "") || "GET"; if (typeof process.env.VERBOSE !== "undefined") { console.time(`Loaded ${sourcefile}`); } var Handler; try { Handler = await import(sourcefile); } catch (e: any) { console.error("Error loading sourcefile:", e); try { await fetch(new URL(`http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/init/error`).href, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ errorMessage: e.message, errorType: e.name, stackTrace: e?.stack?.split("\n") ?? [], }), }); } catch (e2) { console.error("Error sending error to runtime:", e2); } process.exit(1); } if (typeof process.env.VERBOSE !== "undefined") { console.timeEnd(`Loaded ${sourcefile}`); } const handlerFunction = Handler.default?.fetch; if (typeof handlerFunction !== "function") { const e = new Error(`${sourcefile} must export default a function called fetch Here is an example: export default { fetch(req) { return new Response("Hello World"); } } `); console.error(e); try { await fetch(new URL(`http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/init/error`).href, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ errorMessage: e.message, errorType: e.name, stackTrace: e?.stack?.split("\n") ?? [], }), }); } catch (e2) { console.error("Error sending error to runtime:", e2); } process.exit(1); } var baseURLString = AWS_LAMBDA_RUNTIME_API; if ("baseURI" in Handler.default) { baseURLString = Handler.default.baseURI?.toString(); } var baseURL; try { baseURL = new URL(baseURLString); } catch (e: any) { console.error("Error parsing baseURI:", e); try { await fetch(new URL(`http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/init/error`).href, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ errorMessage: e.message, errorType: e.name, stackTrace: e?.stack?.split("\n") || [], }), }); } catch (e2) { console.error("Error sending error to runtime:", e2); } process.exit(1); } async function runHandler(response: Response) { const traceID = response.headers.get("Lambda-Runtime-Trace-Id"); const requestID = response.headers.get("Lambda-Runtime-Aws-Request-Id"); var request = new Request(baseURL.href, { method, headers: response.headers, body: parseInt(response.headers.get("Content-Length") || "0", 10) > 0 ? await response.blob() : undefined, }); // we are done with the Response object here // allow it to be GC'd (response as any) = undefined; var result: Response; try { if (typeof process.env.VERBOSE !== "undefined") { console.time(`[${traceID}] Run ${request.url}`); } result = handlerFunction(request, {}); if (result && (result as any).then) { await result; } } catch (e1: any) { if (typeof process.env.VERBOSE !== "undefined") { console.error(`[${traceID}] Error running handler:`, e1); } fetch(`http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/${requestID}/error`, { method: "POST", body: JSON.stringify({ errorMessage: e1.message, errorType: e1.name, stackTrace: e1?.stack?.split("\n") ?? [], }), }).finally(noop); return; } finally { if (typeof process.env.VERBOSE !== "undefined") { console.timeEnd(`[${traceID}] Run ${request.url}`); } } if (!result || !("headers" in result)) { await fetch(`http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/${requestID}/error`, { method: "POST", body: JSON.stringify({ errorMessage: "Expected Response object", errorType: "ExpectedResponseObject", stackTrace: [], }), }); return; } await fetch(`http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/${requestID}/response`, { method: "POST", headers: result.headers, body: await result.blob(), }); (result as any) = undefined; } while (true) { fetch(nextURL).then(runHandler, console.error); } export {}; fix-prepare-stack-trace Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/test/snippets/lodash-regexp.js (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2023-03-02only free sink after promises solves (#2268)Gravatar Ciro Spaciari 2-10/+10
2023-03-02Fix `Bun.sleepSync` to actually use milliseconds (#2242)Gravatar Justin Whear 3-5/+57
2023-03-01fix(bindings): mark `JSCInitialize` (#2265)Gravatar Derrick Farris 1-0/+1
2023-03-01Add page descriptions (#2260)Gravatar Colin McDonnell 1-46/+132
2023-03-01fix bun server segfault with abortsignal (#2261)Gravatar Ciro Spaciari 3-133/+79
2023-03-01fix(node:http): match Node `http.request()` GET/HEAD w/ body (#2262)Gravatar Derrick Farris 2-2/+31
2023-03-01Add a test for https request in node:httpGravatar Jarred Sumner 2-17/+28
2023-03-01fix(node:http/https): fix passing `URL` objs to `http.request`(#2253) (#2258)Gravatar Derrick Farris 2-43/+63
2023-03-01Revert "Update clap (#2238)"Gravatar Jarred Sumner 16-290/+1840
2023-03-01Revert "Add `-D`, `--dev` flags for bun install (#2240)"Gravatar Jarred Sumner 1-9/+9
2023-03-01Use GitHub action ID instead of SHA for test workflowGravatar Ashcon Partovi 1-1/+1
2023-03-01avoids segfault after aborted onReject in Bun.serve streams (#2256)Gravatar Ciro Spaciari 1-7/+8
2023-03-01Run tests in CI for bun-linux-aarch64Gravatar Ashcon Partovi 2-1/+30
2023-03-01Revert spawnSync changeGravatar Jarred Sumner 1-1/+2
2023-03-01Update bindings.zigGravatar Jarred Sumner 1-1/+3
2023-03-01fix deinit behavior when connection is aborted using ResponseStream and abort...Gravatar Ciro Spaciari 3-34/+174
2023-03-01fix Bun.file.arrayBuffer() segmentation fault on empty file #2248 (#2249)Gravatar Ciro Spaciari 3-7/+23
2023-03-01Fix async in sqliteGravatar Colin McDonnell 1-2/+2
2023-02-28Forces a specific libdir for c-ares (#2241)Gravatar Justin Whear 1-1/+5
2023-02-28Make Bun.gc(true) more aggressiveGravatar Jarred Sumner 1-0/+3
2023-02-28Expose JSC::Options via `BUN_JSC_` prefixGravatar Jarred Sumner 6-8/+47
2023-02-28fixupGravatar Jarred Sumner 1-1/+1
2023-02-28Fix typecheckGravatar Colin McDonnell 2-1/+4
2023-02-28Fix incorrect Bun version in docs (#2236)Gravatar Derrick Farris 1-1/+1
2023-02-28just some comments fix (#2237)Gravatar Ciro Spaciari 1-4/+2
2023-02-28Add `-D`, `--dev` flags for bun install (#2240)Gravatar Justin Whear 1-9/+9
2023-02-28Document punningGravatar Colin McDonnell 1-1/+18