mirror of
https://github.com/movie-web/simple-proxy.git
synced 2025-09-13 14:03:27 +00:00
fix linter + make proxy work + remove temp files + fix typescript types
This commit is contained in:
22
src/routes/index.ts
Normal file
22
src/routes/index.ts
Normal 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);
|
||||
},
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user