/**
* Cloudflare Workers Configuration
* Deploy serverless functions at the edge
*/
// wrangler.toml
/*
name = "my-worker"
main = "src/index.ts"
compatibility_date = "2024-01-01"
[vars]
ENVIRONMENT = "production"
[[kv_namespaces]]
binding = "KV_STORE"
id = "your-kv-namespace-id"
[[d1_databases]]
binding = "DB"
database_name = "my-database"
database_id = "your-database-id"
[observability]
enabled = true
*/
// Example Worker with Hono
import { Hono } from "hono";
type Bindings = {
KV_STORE: KVNamespace;
DB: D1Database;
};
const app = new Hono<{ Bindings: Bindings }>();
app.get("/", (c) => c.text("Hello from Cloudflare Workers!"));
app.get("/kv/:key", async (c) => {
const key = c.req.param("key");
const value = await c.env.KV_STORE.get(key);
return c.json({ key, value });
});
app.post("/kv/:key", async (c) => {
const key = c.req.param("key");
const { value } = await c.req.json();
await c.env.KV_STORE.put(key, value);
return c.json({ success: true });
});
export default app;