Next.js Discord

Discord Forum

Fetching from Next.JS Route Handler from a route handler itself

Unanswered
Small Münsterländer posted this in #help-forum
Open in Discord
Small MünsterländerOP
So I have this function that gets some numbers from another function

Now I am using typescript and NextJS 14

Problem is, how do I access the overallMatches.matches object?

The route /api/last10/matches returns a json from prisma

export const getPlayerPerformance = cache(async (player_id: string, surface: string) => {
    const time_0 = performance.now();

    // const overallMatches = await cachedLatestMatches(player_id, surface)
    const overallMatches = await fetch(`/api/last10/matches?id=${player_id}&surface=${surface}`, {method: "GET"})

    console.log("matches:", overallMatches.matches.length)

    const time_1 = performance.now();
    console.log(player_id, surface, "Time to fetch matches: ", time_1 - time_0, "ms");

    const [overall_perf] = await Promise.all([
        getPerformance(overallMatches.matches.slice(0, 10), player_id),
    ]);

    return {
        perf_surface: overall_perf.perf_surface,
    };
});

5 Replies

Small MünsterländerOP
I'm getting this error Property 'matches' does not exist on type 'Response'.ts(2339)
Small MünsterländerOP
lol got it
need to create another variable
then parse overallMatches as json
so res = overallMatches.json()