풀스택 엣지 아키텍처
Hono + D1(SQLite) + R2(스토리지)로 모든 것이 엣지에서 동작하는 앱을 만듭니다.
구현
import { Hono } from "hono";
import { drizzle } from "drizzle-orm/d1";
type Bindings = { DB: D1Database; BUCKET: R2Bucket };
const app = new Hono<{ Bindings: Bindings }>();
app.get("/api/posts", async (c) => {
const db = drizzle(c.env.DB);
const posts = await db.select().from(postsTable);
return c.json(posts);
});
app.post("/api/upload", async (c) => {
const file = await c.req.blob();
await c.env.BUCKET.put("uploads/" + file.name, file);
return c.json({ ok: true });
});
댓글 0