Skip to content

No baseUrl when calling API from RSC #18

@CarrettaRiccardo

Description

@CarrettaRiccardo

Calling a test api from a RSC returns Error: Failed to parse URL from /api/test, as there is no http://localhost:3000 prefix in the fetch call from the server.

Example code in app/page.tsx:

import { getApitest } from "@/routes";

export default async function Home() {
  const x = await getApitest() // error

  return (
    <main className="">
      {x.message}
    </main>
  );
}

Example API in app/api/test/route.ts:

import { NextResponse } from "next/server";

export async function GET() {
    return NextResponse.json({ message: "Hello, World!" });
}

Generated code in routes/index.ts:

export const getApitest = makeGetRoute(
  "/api/test",
  {
    ...defaultInfo,
    ...ApitestRoute.Route
  },
  ApitestRoute.GET
);

I guess createRouteBuilder function should understand when to return the env.NEXT_PUBLIC_URL for APIs, or just always return it

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions