I use deployment protection for all deployments except the current production deployment. To handle errors in my backend I have some error classes that send a POST request using the fetch api to an error logging endpoint in my app. This fetch request is made from the error class constructor. This works perfectly in local development but not in protected deployments. I have tried to add the bypass protection header, which allows me to bypass the protection for test requests sent via postman, but for some reason the requests don't work when they are sent from the error constructor, which is called from a nextjs server action (ie a serverless function). I added logging to my middleware and I can see, that the POST request is never received neither in middleware or the actual endpoint. It just never resolves and hangs infinitely unless i add a timeout signal.
The fetch request is made thus
const url = new URL("/api/v1/error/log", getEnvironmentUrlBase())const res = await fetch(url, { method: "POST", body: JSON.stringify(this.data), headers: { "Content-Type": "application/json", "X-LoggingApiKey": `${process.env.LOGGING_API_KEY}`, "x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET ?? "", }, })Again this code works perfectly in local development but the fetch request is never arriving in preview with deployment protection. I have verified that this works fine with deployment protection is disabled. Also I don't use the VERCEL_URL system environment variable, which according to the docs doesn't work with deployment protection, i use the host header to send the request to the same origin as the incoming request:
export function getEnvironmentUrlBase() { if (process.env.NODE_ENV === "development") { return `http://localhost:3000` } return `https://${headers().get("host") || BASE_PROD_URL}`}Based on a bunch of logging statements i have verified, that the request is formatted correctly and sent to the right url with the right api key and protection bypass header.
I hope that someone can help identify the problem, because I am out of ideas. Let me know if other information is needed. Thanks in advance