Api route 404s with stripe
Unanswered
SpicyJungle posted this in #help-forum
Hey, I can't understand why this 404s. It used to work:
/purchase/[item]/page.tsxexport default function Page({ params }: { params: { item: string } }) {
const router = useRouter();
const fetcher = (url: string) => fetch(url).then((res) => res.json());
const { data, error, isLoading } = useSWR("/api/auth/session", fetcher);
const session = data as Session;
const [clientSecret, setClientSecret] = useState("");
useEffect(() => {
fetch("/api/checkout_sessions", {
method: "POST",
body: JSON.stringify({ quantity: 1, item: params.item }),
})
.then((res) => res.json())
.then((data) => setClientSecret(data.clientSecret));
}, [params.item]);
...api/checkout_sessions/route.tsimport { NextRequest, NextResponse } from "next/server";
const stripe = require("stripe")(process.env.STRIPE_SECRET);
export const runtime = "edge"; // 'nodejs' is the default
export async function handler(req: NextRequest) {
// This does not trigger:
console.log("in checkout_sessions/route.ts")
... handling req4 Replies
@Ray the name should be POST
ts
export async function POST(req: NextRequest) {}
Sorry, forgot to include but I do
export { handler as GET, handler as POST }; at the bottomI tried removing "export" on the function declaration
but same story