Initial commit
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { FrappeError, METHODS, frappeCall } from '@/lib/lukenya-api'
|
||||
|
||||
// POST { token } → the runner's entry. POST { email } → email a fresh My Race link.
|
||||
// Tokens travel in the request body, not the URL, so they don't end up in access logs.
|
||||
export async function POST(req: Request) {
|
||||
const body = await req.json().catch(() => ({}))
|
||||
try {
|
||||
if (typeof body.token === 'string' && body.token) {
|
||||
const entry = await frappeCall<Record<string, unknown>>(METHODS.myRace, { args: { token: body.token }, post: true })
|
||||
return NextResponse.json(entry, { headers: { 'Cache-Control': 'no-store' } })
|
||||
}
|
||||
if (typeof body.email === 'string' && body.email.includes('@')) {
|
||||
const result = await frappeCall<{ message: string }>(METHODS.myRaceLink, {
|
||||
args: { email: body.email.trim().toLowerCase() },
|
||||
post: true,
|
||||
})
|
||||
return NextResponse.json(result)
|
||||
}
|
||||
return NextResponse.json({ error: 'Enter the email you registered with.' }, { status: 400 })
|
||||
} catch (err) {
|
||||
const status = err instanceof FrappeError && err.status < 500 ? err.status : 502
|
||||
return NextResponse.json({ error: (err as Error).message }, { status })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user