Fetch with "no-store" cache does not refetch.
Answered
Hexaa Scoooolzs posted this in #help-forum
So, my API routes has a something to do to Discord Webhook. this is the code:
when i do refresh/go into the api on Development mode, the webhook successfully created.
when i do refresh/go into the api on Production mode, the webhook does not posted. Why? Even i'm use the (
import config from "@/config";
import { NextApiRequest, NextApiResponse } from "next";
export async function GET(req: NextApiRequest, res: NextApiResponse) {
const response = await fetch(
"https://discord.com/api/webhooks/example/example",
{
cache: "no-store",
method: "POST",
body: JSON.stringify({
embeds: [
{
description: "example",
},
],
}),
headers: {
"Content-Type": "application/json",
},
}
);
const data = await response.json();
console.log(data, response);
return Response.json(
{ success: response.statusText !== "Bad Request" },
{ status: 201 }
);
}when i do refresh/go into the api on Development mode, the webhook successfully created.
when i do refresh/go into the api on Production mode, the webhook does not posted. Why? Even i'm use the (
cache: "no-store").16 Replies
@Ray put `export const dynamic = "force-dynamic"` to it
okay, works perfectly
since GET are cached by default. that's why we need to force-dynamic
@Ray btw the function should look like this
ts
export async function GET(req: Request) {}
ooh, i thought it will be same like pages router
and with no eslint error. thats why i put it like that
https://nextjs.org/docs/app/building-your-application/routing/route-handlers
you can learn more in here😀
you can learn more in here😀
@Ray https://nextjs.org/docs/app/building-your-application/routing/route-handlers
you can learn more in here😀
alr! thanks for your support 🫡
np, please mark solution if you issue has been solved
right click the answer > application > mark solution
@Ray right click the answer > application > mark solution
weird, after refreshing discord, the "No Commands Available" still pop up.
oh i'm not sure about it.
nevermind it😀
Tonkinese
ty for this solution i search since 2 days for fix it