add node, got a couple endpoints working
This commit is contained in:
7
src/pages/api/entry/all.ts
Normal file
7
src/pages/api/entry/all.ts
Normal 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))
|
||||
}
|
||||
23
src/pages/api/entry/new.ts
Normal file
23
src/pages/api/entry/new.ts
Normal 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 });
|
||||
}
|
||||
Reference in New Issue
Block a user