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