From 9ef1467ee1948e8dc181ce3146cf5d45a1a0bf07 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Wed, 20 Dec 2023 14:37:34 +0100 Subject: [PATCH] Finish ip fetching --- README.md | 3 +++ src/utils/ip.ts | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1c69650..5df460f 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,9 @@ Read the docs at https://docs.movie-web.app/proxy - bypass CORS - always allows browser to send requests through it - secure it with turnstile - prevent bots from using your proxy +> [!WARNING] +> Turnstile integration only works properly with cloudflare workers as platform + ### supported platforms: - cloudflare workers - AWS lambda diff --git a/src/utils/ip.ts b/src/utils/ip.ts index 017b868..65d48b4 100644 --- a/src/utils/ip.ts +++ b/src/utils/ip.ts @@ -1,5 +1,10 @@ import { EventHandlerRequest, H3Event } from 'h3'; -export function getIp(_event: H3Event) { - return 'not-a-real-ip'; // TODO cross platform IP +export function getIp(event: H3Event) { + const value = getHeader(event, 'CF-Connecting-IP'); + if (!value) + throw new Error( + 'Ip header not found, turnstile only works on cloudflare workers', + ); + return value; }