Skip to content

Commit d4929a7

Browse files
committed
Waitlist API: added
1 parent a2e3ee6 commit d4929a7

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

app/api/waitlist/route.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { NextResponse } from "next/server"
2+
3+
import { db } from "@/drizzle.config"
4+
import { waitlist } from "@/app/api/schema"
5+
6+
export async function GET() {
7+
try {
8+
const allWaitlist = await db.select().from(waitlist)
9+
return NextResponse.json(allWaitlist, { status: 200 })
10+
} catch (error) {
11+
console.error("Error fetching waitlist:", error)
12+
return NextResponse.json(
13+
{ error: "Failed to fetch waitlist" },
14+
{ status: 500 }
15+
)
16+
}
17+
}
18+
19+
export async function POST(request: Request) {
20+
try {
21+
const body = await request.json()
22+
const { email } = body
23+
24+
await db.insert(waitlist).values({ email })
25+
26+
return NextResponse.json({ message: "Joined waitlist!" }, { status: 200 })
27+
} catch (error) {
28+
console.error("Error processing request:", error)
29+
return NextResponse.json(
30+
{
31+
message: "Something went wrong!",
32+
error: "Failed to process request",
33+
},
34+
{ status: 400 }
35+
)
36+
}
37+
}

0 commit comments

Comments
 (0)