feat(proxy): add environment config and request handling

- Introduce environment-based configuration for proxy settings
- Add middleware for API key authentication
- Implement request forwarding to LanguageTool backend
- Set up server startup and routing logic
This commit is contained in:
2025-05-11 01:10:54 +02:00
parent 52ce172ef5
commit f9714cbb53
4 changed files with 131 additions and 0 deletions

21
src/ltProxyAuth.ts Normal file
View File

@@ -0,0 +1,21 @@
import { Middleware } from 'http-kernel/Types/mod.ts';
import { Env } from './env.ts';
/**
* Middleware that checks for a valid API key via ?apiKey=... query/form param.
* Rejects request with 403 if the key is missing or invalid.
*/
export const authMiddleware: Middleware = async (ctx, next) => {
const key = ctx.query.apiKey;
// Support both ?apiKey=... and form body with apiKey=...
const extractedKey = Array.isArray(key) ? key[0] : key;
if (!extractedKey || !Env.apiKeys.includes(extractedKey)) {
return new Response('Forbidden – Invalid API key', { status: 403 });
}
return await next();
};
export { authMiddleware as ltProxyAuth };