#'cache: no store' not working in Production - App router

40 messages · Page 1 of 1 (latest)

oblique tundraBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

late basalt
#

because the route itself is static

#

try add export const dynamic = "force-dynamic"

#

yep

red harbor
#

@late basalt thank you - so based on the docs, if I changed to .ts and used the below that should also work?

    const token = process.env.API_WEATHER_TOKEN; // Your API token
    const url = `https://api.apify.com/v2/acts/shanes~tweet-flash/runs/last/dataset/items?token=${token}`;

    try {
        const response = await fetch(url, { cache: 'no-store' });
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }
        const data = await response.json();

        return NextResponse.json(data, { status: 200 });
    } catch (error) {
        return NextResponse.json({ error: error.message }, { status: 500 });
    }
}```
late basalt
#

oh wait, are you using app router or page router?

red harbor
#

App Router

late basalt
#

because i saw the path is // pages/api/get_weather.js

red harbor
#

sorry that comment is wrong, it's app router

red harbor
#

Just to confirm, both options should work on App router?

late basalt
#

export const dynamic = "force-dynamic" this only work in app router

#

I think the api route in page router is dynamic by default

red harbor
#

got it, thanks again

late basalt
#

does it fix your issue?

red harbor
#

I believe so, but i wont know for sure until tomorrow morning when data updates and cron job runs

late basalt
#

ah ok

red harbor
#

@late basalt im not really understanding what cache: no store does vs the force dynamic, any chance you can share more?

late basalt
#

cache: no store only cache the fetch result

#

but the problem is your route is static generated

red harbor
#

ok gotcha, ill have to dig more into it

late basalt
#

there is a report after you run next build

#

you should see that route is static generated

red harbor
#

is the report in the console or where?

late basalt
#

in the console

#

it will print after the build finish

red harbor
#

ahh the symbol

#

thanks

late basalt
#

yea

#

from the report, you have two api is static too

red harbor
#

so /cron I want to always update

#

that says sever so should be good

#

ill check the others

#

thanks again

red harbor
#

@late basalt this worked, big thanks!

late basalt
red harbor
#

How do I do that? First time using this

late basalt
#

right click my answer > application > mark solution