From: Ardis Lu Date: Tue, 14 Sep 2021 04:33:42 +0000 (-0700) Subject: Add IP worker X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=2873974ad62e997b177134125f64a4710436dc9d;p=cloudflare-workers Add IP worker --- diff --git a/README.md b/README.md index e724787..d98b15c 100644 --- a/README.md +++ b/README.md @@ -117,3 +117,21 @@ Generates a QR code for the value passed to the endpoint. Note: set the `type` p ### Usage Same as `proxy`. + +## ip + +Returns the requester's IP address. Uses the [Cloudflare header](https://developers.cloudflare.com/workers/runtime-apis/headers#cloudflare-headers) `CF-Connecting-IP` to get this value. Inspired by and works like [ifconfig.me](https://ifconfig.me) and [ifconfig.co](https://ifconfig.co). + +### Usage + +In bash: +``` +curl https://x.y.workers.dev +> +``` + +In PowerShell: +``` +(Invoke-WebRequest https://x.y.workers.dev).Content +> +``` diff --git a/ip/index.js b/ip/index.js new file mode 100644 index 0000000..d573cb8 --- /dev/null +++ b/ip/index.js @@ -0,0 +1,3 @@ +addEventListener('fetch', event => { + event.respondWith(new Response(event.request.headers.get('CF-Connecting-IP'))); +}) diff --git a/ip/package.json b/ip/package.json new file mode 100644 index 0000000..84cdf42 --- /dev/null +++ b/ip/package.json @@ -0,0 +1,19 @@ +{ + "name": "ip", + "version": "0.1.0", + "description": "Cloudflare Worker which returns the requester's IP address.", + "private": true, + "main": "index.js", + "scripts": { + "login": "wrangler login", + "preview": "wrangler preview", + "build": "wrangler build", + "publish": "wrangler publish" + }, + "author": "Ardis Lu", + "license": "ISC", + "repository": { + "type": "git", + "url": "https://github.com/ardislu/cloudflare-workers.git" + } +} diff --git a/ip/wrangler.toml.example b/ip/wrangler.toml.example new file mode 100644 index 0000000..9ff38c2 --- /dev/null +++ b/ip/wrangler.toml.example @@ -0,0 +1,5 @@ +name = 'ip' +type = 'javascript' +account_id = '' +workers_dev = true +route = 'example.com/*' diff --git a/package.json b/package.json index 8956dc3..468272e 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "instagram", "cors", "pwned", - "qr" + "qr", + "ip" ] }