Last active
January 2, 2020 23:08
-
-
Save ZE3kr/c7eb7735ee779d63996415c150591867 to your computer and use it in GitHub Desktop.
Demo: https://api.tloxygen.com/ip (Use Cloudflare by default, UPYUN for China) or http://api.tloxygen.net/ip (Only use Cloudflare)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addEventListener('fetch', event => { | |
event.respondWith(fetchAndApply(event.request)) | |
}) | |
async function fetchAndApply(request) { | |
if(request.url === 'https://api.tloxygen.com/ip' || request.url === 'http://api.tloxygen.com/ip') { | |
const ip = request.headers.get('cf-connecting-ip') | |
return new Response(ip) | |
} else if (request.url === 'https://api.tloxygen.com/country' || request.url === 'http://api.tloxygen.com/country') { | |
const ip = request.headers.get('cf-ipcountry') | |
return new Response(ip) | |
} else if (request.url === 'https://api.tloxygen.com/ipjson' || request.url === 'http://api.tloxygen.com/ipjson') { | |
const ip = '{"ip":"' + request.headers.get('cf-connecting-ip') + '","country":"' + request.headers.get('cf-ipcountry') + '"}' | |
return new Response(ip) | |
} else { | |
return new Response('Sorry, this page is not available.', | |
{ status: 404 }) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$WHEN($EQ($_URI,'/ip'))$DEL_RSP_HEADER(Content-Type)$ADD_RSP_HEADER(Content-Type, text/plain)$ADD_RSP_HEADER(Cache-Control, no-cache)$EXIT(200,$_IP) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment