Next.js Discord

Discord Forum

Fetch with "no-store" cache does not refetch.

Answered
Hexaa Scoooolzs posted this in #help-forum
Open in Discord
So, my API routes has a something to do to Discord Webhook. this is the code:
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").
Answered by Ray
put export const dynamic = "force-dynamic" to it
View full answer

16 Replies

Answer
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
np, please mark solution if you issue has been solved
@Ray np, please mark solution if you issue has been solved
new issue but not related to nextjs.. nvm i get it
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