add node, got a couple endpoints working

This commit is contained in:
2026-01-12 16:54:30 +13:00
parent e448e68c1d
commit 02df7ab9e4
6 changed files with 180 additions and 2 deletions

View File

@@ -0,0 +1,7 @@
import { db, Entry } from "astro:db";
export async function GET() {
const entries = await db.select().from(Entry)
return new Response(JSON.stringify(entries))
}

View File

@@ -0,0 +1,23 @@
import { db, Entry } from "astro:db";
export async function POST({ request }) {
if (request.headers.get("Content-Type") === "application/json") {
try {
const body = await request.json();
await db.insert(Entry).values(body)
} catch(e) {
return new Response(
JSON.stringify({
"error": `Malformed JSON (${e})`
}),{ status: 400 }
)
}
return new Response(null, { status: 200 });
}
return new Response(null, { status: 400 });
}