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:
21
src/ltProxyAuth.ts
Normal file
21
src/ltProxyAuth.ts
Normal 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 };
|
Reference in New Issue
Block a user