aboutsummaryrefslogtreecommitdiff
path: root/packages/bun-lambda
diff options
context:
space:
mode:
authorGravatar Ashcon Partovi <ashcon@partovi.net> 2023-02-23 09:54:22 -0800
committerGravatar Ashcon Partovi <ashcon@partovi.net> 2023-02-23 09:54:22 -0800
commit2c795e6a3cf8386d77dae040a1d39b1d637e145f (patch)
treed9e4f22cb0eed703483f2e2e87a7cbccb4b9015f /packages/bun-lambda
parent17f1649c87678f1dc80816d9a798c441c607a9ba (diff)
downloadbun-2c795e6a3cf8386d77dae040a1d39b1d637e145f.tar.gz
bun-2c795e6a3cf8386d77dae040a1d39b1d637e145f.tar.zst
bun-2c795e6a3cf8386d77dae040a1d39b1d637e145f.zip
bun-lambda: Fix 502 when handler name was 'fetch'
Diffstat (limited to 'packages/bun-lambda')
-rwxr-xr-xpackages/bun-lambda/runtime.ts15
1 files changed, 9 insertions, 6 deletions
diff --git a/packages/bun-lambda/runtime.ts b/packages/bun-lambda/runtime.ts
index c29462b9b..4b38b6dfa 100755
--- a/packages/bun-lambda/runtime.ts
+++ b/packages/bun-lambda/runtime.ts
@@ -146,20 +146,23 @@ async function init(): Promise<Lambda> {
}
return throwError("InitError", cause);
}
- const moduleName = handlerName.substring(index + 1) || "default";
- let module = file[moduleName];
- if (moduleName !== "default") {
+ const moduleName = handlerName.substring(index + 1) || "fetch";
+ let module = file["default"] ?? file[moduleName] ?? {};
+ if (typeof module === "function") {
module = {
fetch: module,
};
+ } else if (typeof module === "object" && moduleName !== "fetch") {
+ module = {
+ ...module,
+ fetch: module[moduleName],
+ };
}
const { fetch, websocket } = module;
if (typeof fetch !== "function") {
return throwError(
fetch === undefined ? "MethodDoesNotExist" : "MethodIsNotAFunction",
- moduleName === "default"
- ? `${fileName} does not have a default export with a function named 'fetch'`
- : `${fileName} does not export a function named '${moduleName}'`,
+ `${fileName} does not have a default export with a function named '${moduleName}'`,
);
}
if (websocket === undefined) {