export default {
  async fetch(request) {
    const url = new URL(request.url);
    const origin = "https://preview-nomade-portal-5a80e7b1.viktor.space";
    const targetUrl = origin + url.pathname + url.search;

    const resp = await fetch(targetUrl, {
      method: request.method,
      headers: {
        ...Object.fromEntries(request.headers),
        'Host': 'preview-nomade-portal-5a80e7b1.viktor.space',
      },
      body: request.method !== 'GET' && request.method !== 'HEAD'
        ? request.body : undefined,
    });

    const newHeaders = new Headers(resp.headers);
    newHeaders.delete('x-vercel-id');
    newHeaders.delete('x-powered-by');

    return new Response(resp.body, {
      status: resp.status,
      headers: newHeaders,
    });
  }
};