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

28
src/ltProxyHandler.ts Normal file
View File

@@ -0,0 +1,28 @@
import { Handler } from 'http-kernel/Types/mod.ts';
import { Env } from './env.ts';
/**
* Forwards the incoming request to the actual LanguageTool server.
* Dynamically passes through path and query string.
*/
export const handler: Handler = async (ctx) => {
const originalUrl = new URL(ctx.req.url);
const proxyUrl = new URL(
`${originalUrl.pathname}${originalUrl.search}`,
`http://${Env.ltServerHost}:${Env.ltServerPort}`,
);
const forwarded = await fetch(proxyUrl.toString(), {
method: ctx.req.method,
headers: ctx.req.headers,
body: ctx.req.body,
});
const headers = new Headers(forwarded.headers);
return new Response(forwarded.body, {
status: forwarded.status,
headers,
});
};
export { handler as ltProxyHandler };