@@ -16,8 +16,9 @@ const router = Router();
1616router . get ( '/check-vpn' , async ( req , res ) => {
1717 try {
1818 const ip = getClientIp ( req ) ;
19+ const forwarded = req . headers [ 'x-forwarded-for' ] || 'none' ;
1920 const isVpn = await isVpnOrProxy ( ip ) ;
20- res . json ( { vpn : isVpn } ) ;
21+ res . json ( { vpn : isVpn , ip , forwarded } ) ;
2122 } catch {
2223 res . json ( { vpn : false } ) ;
2324 }
@@ -93,13 +94,16 @@ async function fetchWithTimeout(url, options = {}, timeout = 5000) {
9394async function isVpnOrProxy ( ip ) {
9495 if ( ip === '127.0.0.1' || ip === '::1' || ip === '0.0.0.0' ||
9596 ip . startsWith ( '192.168.' ) || ip . startsWith ( '10.' ) || ip . startsWith ( '172.16.' ) ) {
97+ console . log ( '[VPN] Skipping private IP:' , ip ) ;
9698 return false ;
9799 }
98100 try {
99- const res = await fetchWithTimeout ( `https://ip-api.com/json/${ ip } ?fields=proxy,hosting,query` ) ;
101+ const res = await fetchWithTimeout ( `https://ip-api.com/json/${ ip } ?fields=proxy,hosting,isp,org, query` ) ;
100102 const data = await res . json ( ) ;
103+ console . log ( '[VPN] ip-api response for' , ip , ':' , JSON . stringify ( data ) ) ;
101104 return data . proxy === true || data . hosting === true ;
102- } catch {
105+ } catch ( err ) {
106+ console . log ( '[VPN] ip-api failed for' , ip , ':' , err . message ) ;
103107 return false ;
104108 }
105109}
0 commit comments