feat(logging): add debug logs for key validation and request handling
Some checks failed
Auto Changelog & Release / detect-version-change (push) Successful in 5s
Auto Changelog & Release / release (push) Has been skipped
Auto Changelog & Release / changelog-only (push) Successful in 8s
Build and upload Docker nightly image / build-and-push (push) Has been cancelled

- 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
This commit is contained in:
2025-05-11 11:16:22 +02:00
parent 79dfbcf053
commit 3299419726
2 changed files with 8 additions and 0 deletions

View File

@@ -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();
};

View File

@@ -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,