Hijack requests to self and redirect to local URL
This commit is contained in:
20
src/hooks.server.ts
Normal file
20
src/hooks.server.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { type HandleFetch } from "@sveltejs/kit";
|
||||||
|
|
||||||
|
export const handleFetch: HandleFetch = async ({ request, fetch }) => {
|
||||||
|
if (request.url.startsWith('https://maps.owlboard.info')) {
|
||||||
|
const newUrl = request.url.replace('https://maps.owlboard.info', 'http://localhost:3000');
|
||||||
|
|
||||||
|
const headers = new Headers(request.headers);
|
||||||
|
headers.set('host', 'maps.owlboard.info');
|
||||||
|
|
||||||
|
request = new Request(newUrl, {
|
||||||
|
method: request.method,
|
||||||
|
headers: headers,
|
||||||
|
body: request.body,
|
||||||
|
// @ts-ignore - 'duplex' is needed for node fetch with bodies
|
||||||
|
duplex: 'half'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return fetch(request);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user