
developer Chrome Extension&PWA. Casual Bun enjoyer
- Tweets298
- Following237
- Followers19
- Likes1.5K
![import { serve, sql } from "bun"; import App from "./myReactSPA.html"; serve({ routes: { "/*": App, "/api/users/:id": async (req) => { const id = req.params.id; const [user] = await sql`SELECT * FROM users WHERE id = ${id} LIMIT 1`; return Response.json(user); }, "/api/users": { POST: async (req) => { // ... }, }, }, fetch: () => new Response("Not Found", { status: 404 }), });](https://pbs.twimg.com/media/Gj05utSagAAV14Q.jpg?name=small&format=webp)
ALT import { serve, sql } from "bun"; import App from "./myReactSPA.html"; serve({ routes: { "/*": App, "/api/users/:id": async (req) => { const id = req.params.id; const [user] = await sql`SELECT * FROM users WHERE id = ${id} LIMIT 1`; return Response.json(user); }, "/api/users": { POST: async (req) => { // ... }, }, }, fetch: () => new Response("Not Found", { status: 404 }), });

ALT import { s3, file, write } from "bun"; const svg = s3("logo.svg", { accessKeyId: process.env.S3_ACCESS_KEY, secretAccessKey: process.env.S3_SECRET_KEY, endpoint: process.env.S3_ENDPOINT, bucket: process.env.S3_BUCKET, }); // Upload a local file to S3 await write(svg, file("./logo.svg")); // Upload a Response to S3 await write( svg, await fetch("https://bun.sh/logo.svg") ); // Download from S3 as text const text = await svg.text(); // or .json(), .bytes(), etc // Presign a URL const url = svg.presign(); console.log(url);























