aboutsummaryrefslogtreecommitdiff
path: root/packages/bun-lambda/example/lambda.ts
diff options
context:
space:
mode:
authorGravatar Ashcon Partovi <ashcon@partovi.net> 2023-02-22 10:34:16 -0800
committerGravatar GitHub <noreply@github.com> 2023-02-22 10:34:16 -0800
commitee60a5c55cdafc96268efdebb73aedb3a2ac88fa (patch)
tree02b742922a50a76c8598b315b6458095db349672 /packages/bun-lambda/example/lambda.ts
parent2dc85c4e452c9f5faf9f12f16616e36a7b10fbee (diff)
downloadbun-ee60a5c55cdafc96268efdebb73aedb3a2ac88fa.tar.gz
bun-ee60a5c55cdafc96268efdebb73aedb3a2ac88fa.tar.zst
bun-ee60a5c55cdafc96268efdebb73aedb3a2ac88fa.zip
Add runtime layer for Bun on AWS Lambda (#2009)
Diffstat (limited to 'packages/bun-lambda/example/lambda.ts')
-rw-r--r--packages/bun-lambda/example/lambda.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/packages/bun-lambda/example/lambda.ts b/packages/bun-lambda/example/lambda.ts
new file mode 100644
index 000000000..ec96cf6c9
--- /dev/null
+++ b/packages/bun-lambda/example/lambda.ts
@@ -0,0 +1,33 @@
+import type { Server, ServerWebSocket } from "bun";
+
+export default {
+ async fetch(request: Request, server: Server): Promise<Response | undefined> {
+ console.log("Request", {
+ url: request.url,
+ method: request.method,
+ headers: request.headers.toJSON(),
+ body: request.body ? await request.text() : null,
+ });
+ if (server.upgrade(request)) {
+ console.log("WebSocket upgraded");
+ return;
+ }
+ return new Response("Hello from Bun on Lambda!", {
+ status: 200,
+ headers: {
+ "Content-Type": "text/plain;charset=utf-8",
+ },
+ });
+ },
+ websocket: {
+ async open(ws: ServerWebSocket): Promise<void> {
+ console.log("WebSocket opened");
+ },
+ async message(ws: ServerWebSocket, message: string): Promise<void> {
+ console.log("WebSocket message", message);
+ },
+ async close(ws: ServerWebSocket, code: number, reason?: string): Promise<void> {
+ console.log("WebSocket closed", { code, reason });
+ },
+ },
+};