From 32994197261e9ab5a46df5f90f2faed89cd68558 Mon Sep 17 00:00:00 2001 From: "Max P." Date: Sun, 11 May 2025 11:16:22 +0200 Subject: [PATCH] feat(logging): add debug logs for key validation and request handling - Add debug logs for invalid and valid API key masking - Log unsupported content types in middleware - Log forwarded request URLs and response statuses from LT server --- src/ltProxyAuth.ts | 4 ++++ src/ltProxyHandler.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/ltProxyAuth.ts b/src/ltProxyAuth.ts index 6efa503..e38db27 100644 --- a/src/ltProxyAuth.ts +++ b/src/ltProxyAuth.ts @@ -1,5 +1,6 @@ import { Middleware } from 'http-kernel/Types/mod.ts'; import { Env } from './env.ts'; +import { maskApiKey } from './utils.ts'; /** * Middleware that checks for a valid API key via form param. @@ -17,12 +18,15 @@ export const authMiddleware: Middleware = async (ctx, next) => { const key = params.get('apiKey'); if (!key || !Env.apiKeys.includes(key)) { + console.debug('Invalid API key:', maskApiKey(key)); return new Response('Forbidden – Invalid API key', { status: 403 }); } } else { + console.debug('Unsupported content type:', contentType); return new Response('Unsupported content type', { status: 415 }); } + console.debug('Valid API key:', maskApiKey(ctx.req.headers.get('apiKey'))); return await next(); }; diff --git a/src/ltProxyHandler.ts b/src/ltProxyHandler.ts index 8d593e8..7e36423 100644 --- a/src/ltProxyHandler.ts +++ b/src/ltProxyHandler.ts @@ -37,12 +37,16 @@ export const handler: Handler = async (ctx) => { const headers = new Headers(ctx.req.headers); headers.delete('content-length'); + console.debug('Forwarding request to:', proxyUrl.toString()); + const forwarded = await fetch(proxyUrl.toString(), { method: ctx.req.method, headers, body, }); + console.debug('Received response from LT server:', forwarded.status); + const respHeaders = new Headers(forwarded.headers); return new Response(forwarded.body, { status: forwarded.status,