Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
9e1fefaa2f | |||
a79eb29dab
|
|||
5f28d5ca7a | |||
d57cc27e19
|
|||
05fcd4b0f8 | |||
f7b55bb26c
|
|||
0d26bf4cf8 | |||
3299419726
|
|||
79dfbcf053
|
13
CHANGELOG.md
13
CHANGELOG.md
@@ -2,6 +2,19 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [0.4.0](https://git.0xmax42.io/maxp/lt-auth-proxy/compare/v0.3.0..v0.4.0) - 2025-05-11
|
||||||
|
|
||||||
|
### 🚀 Features
|
||||||
|
|
||||||
|
- *(server)* Add graceful shutdown handling - ([d57cc27](https://git.0xmax42.io/maxp/lt-auth-proxy/commit/d57cc27e19e68c13ac08af223c3721a9c45fafd1))
|
||||||
|
|
||||||
|
## [0.3.0](https://git.0xmax42.io/maxp/lt-auth-proxy/compare/v0.2.1..v0.3.0) - 2025-05-11
|
||||||
|
|
||||||
|
### 🚀 Features
|
||||||
|
|
||||||
|
- *(logging)* Add debug logs for key validation and request handling - ([3299419](https://git.0xmax42.io/maxp/lt-auth-proxy/commit/32994197261e9ab5a46df5f90f2faed89cd68558))
|
||||||
|
- *(utils)* Add utility to mask API keys - ([79dfbcf](https://git.0xmax42.io/maxp/lt-auth-proxy/commit/79dfbcf053d613fe3fff63bfd24537a1665c9389))
|
||||||
|
|
||||||
## [0.2.1](https://git.0xmax42.io/maxp/lt-auth-proxy/compare/v0.1.1..v0.2.1) - 2025-05-11
|
## [0.2.1](https://git.0xmax42.io/maxp/lt-auth-proxy/compare/v0.1.1..v0.2.1) - 2025-05-11
|
||||||
|
|
||||||
### 🚀 Features
|
### 🚀 Features
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import { Middleware } from 'http-kernel/Types/mod.ts';
|
import { Middleware } from 'http-kernel/Types/mod.ts';
|
||||||
import { Env } from './env.ts';
|
import { Env } from './env.ts';
|
||||||
|
import { maskApiKey } from './utils.ts';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Middleware that checks for a valid API key via form param.
|
* 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');
|
const key = params.get('apiKey');
|
||||||
|
|
||||||
if (!key || !Env.apiKeys.includes(key)) {
|
if (!key || !Env.apiKeys.includes(key)) {
|
||||||
|
console.debug('Invalid API key:', maskApiKey(key));
|
||||||
return new Response('Forbidden – Invalid API key', { status: 403 });
|
return new Response('Forbidden – Invalid API key', { status: 403 });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
console.debug('Unsupported content type:', contentType);
|
||||||
return new Response('Unsupported content type', { status: 415 });
|
return new Response('Unsupported content type', { status: 415 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.debug('Valid API key:', maskApiKey(ctx.req.headers.get('apiKey')));
|
||||||
return await next();
|
return await next();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -37,12 +37,16 @@ export const handler: Handler = async (ctx) => {
|
|||||||
const headers = new Headers(ctx.req.headers);
|
const headers = new Headers(ctx.req.headers);
|
||||||
headers.delete('content-length');
|
headers.delete('content-length');
|
||||||
|
|
||||||
|
console.debug('Forwarding request to:', proxyUrl.toString());
|
||||||
|
|
||||||
const forwarded = await fetch(proxyUrl.toString(), {
|
const forwarded = await fetch(proxyUrl.toString(), {
|
||||||
method: ctx.req.method,
|
method: ctx.req.method,
|
||||||
headers,
|
headers,
|
||||||
body,
|
body,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.debug('Received response from LT server:', forwarded.status);
|
||||||
|
|
||||||
const respHeaders = new Headers(forwarded.headers);
|
const respHeaders = new Headers(forwarded.headers);
|
||||||
return new Response(forwarded.body, {
|
return new Response(forwarded.body, {
|
||||||
status: forwarded.status,
|
status: forwarded.status,
|
||||||
|
11
src/main.ts
11
src/main.ts
@@ -3,6 +3,7 @@ import { Env } from './env.ts';
|
|||||||
import { ltProxyAuth } from './ltProxyAuth.ts';
|
import { ltProxyAuth } from './ltProxyAuth.ts';
|
||||||
import { ltProxyHandler } from './ltProxyHandler.ts';
|
import { ltProxyHandler } from './ltProxyHandler.ts';
|
||||||
|
|
||||||
|
const ac = new AbortController();
|
||||||
const httpKernel = new HttpKernel();
|
const httpKernel = new HttpKernel();
|
||||||
|
|
||||||
httpKernel.route({
|
httpKernel.route({
|
||||||
@@ -11,9 +12,19 @@ httpKernel.route({
|
|||||||
}).middleware(ltProxyAuth).handle(ltProxyHandler);
|
}).middleware(ltProxyAuth).handle(ltProxyHandler);
|
||||||
|
|
||||||
Deno.serve({
|
Deno.serve({
|
||||||
|
signal: ac.signal,
|
||||||
port: Env.proxyPort,
|
port: Env.proxyPort,
|
||||||
hostname: Env.proxyHost,
|
hostname: Env.proxyHost,
|
||||||
onListen: ({ hostname, port }) => {
|
onListen: ({ hostname, port }) => {
|
||||||
console.info(`lt-auth-proxy listening on ${hostname}:${port}`);
|
console.info(`lt-auth-proxy listening on ${hostname}:${port}`);
|
||||||
},
|
},
|
||||||
}, async (req) => await httpKernel.handle(req));
|
}, async (req) => await httpKernel.handle(req));
|
||||||
|
|
||||||
|
const shutdown = () => {
|
||||||
|
console.info('Shutting down the server...');
|
||||||
|
ac.abort();
|
||||||
|
console.info('Server shut down successfully.');
|
||||||
|
};
|
||||||
|
|
||||||
|
Deno.addSignalListener('SIGINT', shutdown);
|
||||||
|
Deno.addSignalListener('SIGTERM', shutdown);
|
||||||
|
6
src/utils.ts
Normal file
6
src/utils.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
export const maskApiKey = (key: string | null): string => {
|
||||||
|
if (!key) return '*****';
|
||||||
|
return key.length <= 5
|
||||||
|
? '*'.repeat(key.length)
|
||||||
|
: key.slice(0, 5) + '*'.repeat(key.length - 5);
|
||||||
|
};
|
Reference in New Issue
Block a user