fix linter + make proxy work + remove temp files + fix typescript types

This commit is contained in:
mrjvs
2023-09-13 22:54:28 +02:00
parent b18d07a6a5
commit 5a070b4a15
9 changed files with 410 additions and 249 deletions

22
src/routes/index.ts Normal file
View File

@@ -0,0 +1,22 @@
import { getProxyHeaders, getAfterResponseHeaders } from '../utils/headers';
export default defineEventHandler(async (event) => {
// handle cors, if applicable
if (isPreflightRequest(event)) return handleCors(event, {});
// parse destination URL
const destination = getQuery<{ destination?: string }>(event).destination;
if (!destination) throw new Error('invalid destination');
// proxy
await proxyRequest(event, destination, {
fetchOptions: {
redirect: 'follow',
headers: getProxyHeaders(event.headers),
},
onResponse(outputEvent, response) {
const headers = getAfterResponseHeaders(response.headers, response.url);
appendResponseHeaders(outputEvent, headers);
},
});
});