@@ -5,35 +5,45 @@ import {
55import { fetchTopThreeUsersByPullRequests } from '../../utils/fetchTopThreeUsersByPullRequests'
66
77export default async function handler ( req , res ) {
8+ res . setTimeout ( 30000 ) ;
9+
810 res . setHeader ( 'Access-Control-Allow-Origin' , '*' )
911 res . setHeader ( 'Access-Control-Allow-Methods' , 'GET' )
1012 res . setHeader ( 'Access-Control-Allow-Headers' , 'Content-Type' )
1113 res . setHeader ( 'Cache-Control' , 'public, max-age=300' )
1214
1315 try {
14- const message = 'API: Checking DB for cached top three users...'
15- console . log ( message )
16- res . setHeader ( 'X-Debug-Message' , message )
16+ console . log ( 'API: Starting request processing' )
17+ console . log ( 'GitHub Token present:' , ! ! process . env . GITHUB_TOKEN )
1718
1819 let data = await getTopThreeUsersFromDb ( )
20+ console . log ( 'DB Data found:' , ! ! data )
1921
2022 if ( ! data ) {
21- console . log ( 'No cached data found, fetching from GitHub...' )
23+ console . log ( 'Fetching from GitHub...' )
2224 data = await fetchTopThreeUsersByPullRequests ( 'fork-commit-merge/fork-commit-merge' )
25+ console . log ( 'GitHub data fetched:' , ! ! data )
2326
2427 if ( data && data . length > 0 ) {
2528 await storeTopThreeUsersInDb ( data )
29+ console . log ( 'Data stored in DB' )
2630 }
2731 }
2832
2933 if ( ! data || data . length === 0 ) {
34+ console . log ( 'No data available' )
3035 return res . status ( 404 ) . json ( { error : 'No data available' } )
3136 }
3237
38+ console . log ( 'Returning data:' , data . length , 'items' )
3339 return res . status ( 200 ) . json ( data )
3440 } catch ( error ) {
3541 console . error ( 'API route error:' , error )
36- return res . status ( 500 ) . json ( { error : 'Internal Server Error' } )
42+ console . error ( 'Stack trace:' , error . stack )
43+ return res . status ( 500 ) . json ( {
44+ error : 'Internal Server Error' ,
45+ message : error . message ,
46+ stack : process . env . NODE_ENV === 'development' ? error . stack : undefined
47+ } )
3748 }
3849}
39-
0 commit comments