deckhearth/api/v1/cards/[id].ts
Randall Stillwell 6b81ed38b0 🚀 TCG Vault - Complete All-Vercel Setup
 Features:
- Camera OCR card scanning with Tesseract.js
- Beautiful glowing card effects and animations
- Intelligent card matching and recognition
- Mobile-responsive design with Tailwind CSS

🏗️ Architecture:
- Frontend: React TypeScript application
- Backend: Vercel Functions (replacing FastAPI)
- Database: JSON file with exported card data
- Deployment: Single Vercel project

📁 Structure:
- api/ - Vercel Functions backend endpoints
- src/ - React frontend components and logic
- src/data/cards.json - Card database (12 cards)
- vercel.json - Optimized Vercel configuration

💰 Cost: /bin/zsh additional (uses existing Vercel Pro)
🚀 Ready for immediate Vercel deployment
2025-07-21 13:53:06 -05:00

89 lines
2.1 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import cardsData from '../../../src/data/cards.json'
interface Card {
id: number
name: string
set_name?: string
set_code?: string
card_number?: string
rarity?: string
game: string
mana_cost?: string
cmc?: number
card_type?: string
colors?: string[]
oracle_text?: string
flavor_text?: string
power?: string
toughness?: string
artist?: string
image_url?: string
stock_image_url?: string
artwork_crop_coords?: any
current_price?: number
market_price?: number
verified: boolean
created_at?: string
updated_at?: string
}
export default async function handler(req: NextRequest) {
// Enable CORS
const headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
}
if (req.method === 'OPTIONS') {
return new NextResponse(null, { status: 200, headers })
}
try {
const url = new URL(req.url)
const pathSegments = url.pathname.split('/')
const cardId = parseInt(pathSegments[pathSegments.length - 1])
if (isNaN(cardId)) {
return new NextResponse(JSON.stringify({ error: 'Invalid card ID' }), {
status: 400,
headers: {
...headers,
'Content-Type': 'application/json',
},
})
}
const cards: Card[] = cardsData as Card[]
const card = cards.find(c => c.id === cardId)
if (!card) {
return new NextResponse(JSON.stringify({ error: 'Card not found' }), {
status: 404,
headers: {
...headers,
'Content-Type': 'application/json',
},
})
}
return new NextResponse(JSON.stringify(card), {
status: 200,
headers: {
...headers,
'Content-Type': 'application/json',
},
})
} catch (error) {
console.error('API Error:', error)
return new NextResponse(JSON.stringify({ error: 'Internal server error' }), {
status: 500,
headers: {
...headers,
'Content-Type': 'application/json',
},
})
}
}