export default { async fetch(request) { const url = new URL(request.url); // Use startsWith to accommodate both /m and /m/ paths const pathStartsWithM = url.pathname.startsWith('/m'); const userAgent = request.headers.get('User-Agent') || ''; const clientIP = request.headers.get('CF-Connecting-IP'); // Identify a list of specific user agents for special handling const specialUserAgents = [ 'curl', 'wget', 'WindowsPowerShell', 'Go-http-client', 'Lynx', 'libwww-perl', 'libcurl-agent', 'Java', 'PycURL', 'PECL::HTTP', 'ddclient' ]; // Check if the user agent matches any in the list or the path starts with /m const isSpecialUserAgent = specialUserAgents.some(ua => userAgent.includes(ua)); if (pathStartsWithM || isSpecialUserAgent) { return new Response(clientIP); } // Generate HTML content with IP information for all other paths const htmlContent = generateIPInfoHTML(request); const htmlStyle = ` body { padding: 6em; background-color: #222831; color: #ececec; } .light-mode { background-color: white; color: black; } `; const html = ` Your IP Information

Your IP Information

${htmlContent}

For a minimal ip page go to Minimal Page

`; return new Response(html, { headers: { "content-type": "text/html;charset=UTF-8" }, }); } } function generateIPInfoHTML(request) { const cf = request.cf || {}; const headers = request.headers; let htmlContent = `

IP: ${headers.get('CF-Connecting-IP')}

Country: ${cf.country}

User Agent: ${headers.get('User-Agent')}

Geolocation Data

Colo: ${cf.colo}

City: ${cf.city}

PostalCode: ${cf.postalCode}

MetroCode: ${cf.metroCode}

Timezone: ${cf.timezone}

Region: ${cf.region}

RegionCode: ${cf.regionCode}

Continent: ${cf.continent}

Latitude: ${cf.latitude}

Longitude: ${cf.longitude}

`; return htmlContent; }