Below you can find a Cloudflare Worker that returns the IP of the client. This is useful if you want to know the IP of the client, for example if you want to block a specific IP.
1addEventListener('fetch', event => {
2 event.respondWith(handleRequest(event.request))
3})
4
5async function handleRequest(request) {
6 return new Response(request.headers.get('cf-connecting-ip'), {
7 headers: { 'content-type': 'text/plain' },
8 })
9}

