Theo's Typesafe CultTTC
Theo's Typesafe Cult4y ago
3 replies
asheeshh

Next.js API route error in prod

so, basically I have an API route which throws error (500) only in prod, it works fine on dev server, I even built the app locally but it works just fine.

Code -
import type { NextRequest } from "next/server";
import { getAnalytics } from "../../lib/umami";

export const config = {
  runtime: "experimental-edge",
};

type UmamiResponse = {
  pageviews: {
    value: number;
  };
  uniques: {
    value: number;
  };
};

export default async function handler(req: NextRequest) {
  const resp = await getAnalytics();
  const analytics = (await resp.json()) as UmamiResponse;

  return new Response(JSON.stringify(analytics), {
    status: 200,
    headers: {
      "Content-Type": "application/json",
      "cache-control": "public, s-maxage=60, stale-while-revalidate=30",
    },
  });
}
Was this page helpful?