mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
Add runtime layer for Bun on AWS Lambda (#2009)
This commit is contained in:
33
packages/bun-lambda/example/lambda.ts
Normal file
33
packages/bun-lambda/example/lambda.ts
Normal file
@@ -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 });
|
||||
},
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user