Files
davila7__claude-code-templates/sync-api.sh
T
Dani 2f78c335e8 Fix: Add serverless function to docs/api for Vercel deployment
The download tracking was failing because Vercel serves from /docs/ as
the outputDirectory. Serverless functions must be inside this directory
to be detected and deployed correctly.

Changes:
- Copy track-download-supabase.js to docs/api/
- Copy package.json with dependencies to docs/api/
- Add comprehensive README.md explaining API structure
- Create sync-api.sh script for easy maintenance
- Keep /api/ as source of truth, /docs/api/ for deployment

This fixes the 404 error on:
https://www.aitmpl.com/api/track-download-supabase

Technical details:
- vercel.json has "outputDirectory": "docs"
- Vercel only detects functions inside the output directory
- Both static files (agents.json) and serverless functions now coexist
- Environment variables (SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY) required

Testing:
After Vercel deployment, test with:
curl -X POST https://www.aitmpl.com/api/track-download-supabase \
  -H "Content-Type: application/json" \
  -d '{"type":"agent","name":"test","path":"test","category":"test"}'

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 09:50:49 -04:00

51 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# sync-api.sh - Sync API files from /api to /docs/api
# This ensures serverless functions are deployed correctly with Vercel
set -e
echo "🔄 Syncing API files from /api to /docs/api..."
echo ""
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Check if source files exist
if [ ! -f "api/track-download-supabase.js" ]; then
echo "❌ Error: api/track-download-supabase.js not found"
exit 1
fi
if [ ! -f "api/package.json" ]; then
echo "❌ Error: api/package.json not found"
exit 1
fi
# Create docs/api directory if it doesn't exist
mkdir -p docs/api
# Copy files
echo "${BLUE}📄 Copying track-download-supabase.js...${NC}"
cp api/track-download-supabase.js docs/api/
echo "${GREEN}✓ Copied track-download-supabase.js${NC}"
echo "${BLUE}📦 Copying package.json...${NC}"
cp api/package.json docs/api/
echo "${GREEN}✓ Copied package.json${NC}"
echo ""
echo "${GREEN}✅ Sync completed successfully!${NC}"
echo ""
echo "📁 Files synced to docs/api/:"
ls -lh docs/api/ | grep -E "(track-download-supabase.js|package.json)"
echo ""
echo "📝 Next steps:"
echo " 1. Review changes: git diff docs/api/"
echo " 2. Commit changes: git add docs/api/ && git commit -m 'Sync API files'"
echo " 3. Deploy to Vercel: vercel --prod"
echo ""