# /api/revalidate 테스트 가이드 ## 추가된 로그 기능 `/api/revalidate` 엔드포인트에 상세 로그가 추가되었습니다: ### 로그 내용 1. **Revalidation 시작 시간** 2. **캐시 무효화 전 포스트 개수 및 ID 목록** 3. **무효화되는 경로 목록** 4. **캐시 무효화 후 포스트 개수 및 ID 목록** 5. **Before/After 비교** 6. **API 응답에 통계 포함** ### 응답 예시 ```json { "revalidated": true, "timestamp": 1732800000000, "postsBefore": 13, "postsAfter": 14, "pathsRevalidated": 8 } ``` ## 로컬 테스트 방법 ### 1. 개발 서버에서 테스트 ```bash # 개발 서버 시작 cd PlanitAI_Inc_website/nextjs pnpm run dev # 다른 터미널에서 API 호출 curl "http://localhost:3000/api/revalidate?secret=LWCTd22HKmCa8uNqOvaoTYlXoNONFVlhx" ``` ### 2. 프로덕션 빌드에서 테스트 ```bash # 빌드 및 시작 pnpm run build pnpm start # 다른 터미널에서 API 호출 curl "http://localhost:3000/api/revalidate?secret=LWCTd22HKmCa8uNqOvaoTYlXoNONFVlhx" ``` ### 3. POST 메서드로 테스트 ```bash curl -X POST http://localhost:3000/api/revalidate \ -H "x-revalidate-secret: LWCTd22HKmCa8uNqOvaoTYlXoNONFVlhx" \ -H "Content-Type: application/json" \ -d '{"slug": "test-post"}' ``` ## Vercel에서 테스트 ### 1. Vercel에 배포 ```bash git add . git commit -m "Add detailed logging to /api/revalidate" git push ``` ### 2. Vercel Function Logs 확인 1. Vercel Dashboard > 프로젝트 선택 2. "Functions" 탭 클릭 3. `/api/revalidate` 함수 선택 4. "Logs" 확인 ### 3. Vercel에서 API 호출 ```bash # GET 메서드 curl "https://your-site.vercel.app/api/revalidate?secret=LWCTd22HKmCa8uNqOvaoTYlXoNONFVlhx" # POST 메서드 curl -X POST https://your-site.vercel.app/api/revalidate \ -H "x-revalidate-secret: LWCTd22HKmCa8uNqOvaoTYlXoNONFVlhx" ``` ### 4. 실시간 로그 확인 (Vercel CLI) ```bash # Vercel CLI 설치 (없는 경우) npm i -g vercel # 로그인 vercel login # 실시간 로그 확인 vercel logs --follow ``` ## 예상 로그 출력 ### 정상 케이스 ``` ================================================================================ [REVALIDATE-GET] Starting revalidation process (GET method) [REVALIDATE-GET] Timestamp: 2025-11-28T12:00:00.000Z [REVALIDATE-GET] Fetching current posts before cache invalidation... [API] Fetching all posts with per_page=100 [API] WordPress response headers - Total: 14, TotalPages: 1 [API] Raw posts received from WordPress: 14 [API] Posts after filtering by subCategory: 13 [API] Post IDs: 95, 83, 75, 68, 63, 59, 56, 52, 33, 30, 26, 22, 20 [REVALIDATE-GET] Posts before revalidation: 13 [REVALIDATE-GET] Post IDs before: 95, 83, 75, 68, 63, 59, 56, 52, 33, 30, 26, 22, 20 [REVALIDATE-GET] Invalidating cache tag: posts [REVALIDATE-GET] Invalidating paths: - / - /blogs - /blogs/ai - /news - /news/press - /news/media - /news/newservice - /news/event [REVALIDATE-GET] Fetching posts after cache invalidation... [API] Fetching all posts with per_page=100 [API] WordPress response headers - Total: 14, TotalPages: 1 [API] Raw posts received from WordPress: 14 [API] Posts after filtering by subCategory: 13 [API] Post IDs: 95, 83, 75, 68, 63, 59, 56, 52, 33, 30, 26, 22, 20 [REVALIDATE-GET] Posts after revalidation: 13 [REVALIDATE-GET] Post IDs after: 95, 83, 75, 68, 63, 59, 56, 52, 33, 30, 26, 22, 20 [REVALIDATE-GET] ✓ Post count unchanged: 13 [REVALIDATE-GET] Revalidation completed successfully ================================================================================ ``` ### 10개로 제한되는 케이스 (문제 상황) ``` ================================================================================ [REVALIDATE-GET] Starting revalidation process (GET method) [REVALIDATE-GET] Timestamp: 2025-11-28T12:00:00.000Z [REVALIDATE-GET] Fetching current posts before cache invalidation... [API] Fetching all posts with per_page=100 [API] WordPress response headers - Total: 10, TotalPages: 1 ← ⚠️ 여기서 10개만! [API] Raw posts received from WordPress: 10 [API] Posts after filtering by subCategory: 9 [REVALIDATE-GET] Posts before revalidation: 9 ... ``` ## 문제 진단 체크리스트 Vercel 로그를 확인할 때 다음을 체크하세요: ### ✅ 확인 항목 1. **`WordPress response headers - Total: ?`** - 14 이상이면 정상 - 10이면 WordPress API가 10개만 반환하는 것 2. **`Raw posts received from WordPress: ?`** - Total과 같아야 함 - 다르다면 네트워크 문제 3. **`Posts after filtering by subCategory: ?`** - Raw posts - 1 (uncategorized 제외) - 차이가 크다면 필터링 로직 문제 4. **Before/After 비교** - 같으면 정상 (캐시 무효화 성공) - 다르면 새 포스트 추가됨 ## 추가 디버깅 문제가 지속되면 다음도 확인: ### WordPress 플러그인 확인 1. 보안 플러그인 (Wordfence, All In One WP Security 등) 2. 캐시 플러그인 (WP Super Cache, W3 Total Cache 등) 3. REST API 제한 플러그인 ### Vercel IP 화이트리스트 WordPress가 Vercel IP를 차단할 수 있음: - WordPress 관리자 > 보안 플러그인 설정 - Vercel IP 범위 확인 및 허용 ### 직접 WordPress API 테스트 (Vercel에서) Vercel Function에서 직접 WordPress API를 호출하는 테스트 엔드포인트 추가: ```typescript // app/api/test-wp/route.ts export async function GET() { const res = await fetch('https://...wp-json/wp/v2/posts?per_page=100&_embed'); const data = await res.json(); return Response.json({ count: data.length, total: res.headers.get('x-wp-total'), posts: data.map(p => ({ id: p.id, title: p.title.rendered })) }); } ```