Skip to content

No baseUrl when calling API from RSC #18

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions