export async function onRequestPost({ request }: { request: Request }) {
  const body = await request.text();

  const response = await fetch('https://cultscale.org/api/newsletter/subscribe', {
    method: 'POST',
    headers: {
      'Content-Type': request.headers.get('content-type') || 'application/json',
      Accept: 'application/json'
    },
    body
  });

  return new Response(response.body, {
    status: response.status,
    headers: {
      'Content-Type': response.headers.get('content-type') || 'application/json'
    }
  });
}

export async function onRequestOptions() {
  return new Response(null, {
    status: 204,
    headers: {
      Allow: 'POST, OPTIONS'
    }
  });
}
