Next.js Discord

Discord Forum

Error when fetching `/api/revalidate/ticker` but `http://localhost:3000/api/revalidate/ticker` works

Unanswered
Cape lion posted this in #help-forum
Open in Discord
Cape lionOP
Throws out a type error in the logs

src/app/layout.tsx
  const res = await fetch("/api/revalidate/ticker", {
    cache: "no-store",
  });
  const data: CoinTicker = await res.json();


src/app/api/revalidate/ticker/route.ts
import { NextResponse } from "next/server";

export async function GET() {
  const res = await fetch(
    "https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=nano",
    {
      headers: {
        "Content-Type": "application/json",
      },
    }
  );
  const json = await res.json();
  const data = json[0];

  return NextResponse.json({ data });
}

6 Replies

Why? The new app dir already can do most of the things in pages dir
@fuma Why? The new app dir already can do most of the things in pages dir
Cape lionOP
For handling an api that stores the last time that the site has been requested