Custom fetch handler, not working with relative paths

so when using fetch you can do this:
fetch("/api/users)
which is great then you don't have to rely on an envioment varibale or URL changing.

so in my app i have created a custom fetch handler, this sets things like authorization, revalidation and anything else i would want, however it doesn't seem to want to work with relative paths.

Custom request:
interface BaseRequest {
  url: RequestInfo | URL;
  method: "GET" | "POST" | "PUT" | "DELETE";
  data?: any;
  params?: any;
  headers?: HeadersInit;
  nextOptions?: NextFetchRequestConfig;
}

export const Request = async <T>(
  url: string,
  {
    method = "GET",
    data,
    params,
    headers,
    nextOptions,
  }: Partial<BaseRequest> = {}
) => {
  const jwt = new JWT();

  const req = await fetch(url, {
    method: method,
    body: JSON.stringify(data),
    headers: {
      ...headers,
      authorization: await jwt.signJWT(),
    },
    next: {
      ...nextOptions,
      revalidate: 60 * 60 * 24,
    },
  });

  return (await req.json()) as T;
};


so this is what i want to do is
Request("/api/users")
rather then
Reqeust("${baseUrl}/api/users")
beacuse doing this seems to fail in production builds in Vercel as the routes don't exist on the production url

I am using Nextjs and Vercel to deploy my project for anyopne wondering
Was this page helpful?