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
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:
@@ -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();
|
||||
};
|
||||
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user