21 lines
603 B
TypeScript
21 lines
603 B
TypeScript
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-expect-error - 'duplex' is needed for node fetch with bodies
|
|
duplex: 'half'
|
|
});
|
|
}
|
|
|
|
return fetch(request);
|
|
};
|