#fetch not working in production

20 messages · Page 1 of 1 (latest)

tough ore
#

I got a dynamic page [id] and trying to fetch data there. It works in localhost but after building in vercel its not doing anything. This is the code:

const getItems = async (id: string) => {
  try {
    const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/operator/score/items/questionnaire/${id}`, {
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
        Authorization: `Basic ${btoa(`${process.env.NEXT_PUBLIC_API_USERNAME}:${process.env.NEXT_PUBLIC_API_PASSWORD}`)}`,
      },
      cache: 'no-store',
    });

    const data = await response.json();

    return data;
  } catch (error) {
    console.error('Error:', error);
  }
};

const ItemsPage = async ({ params }: { params: { id: string } }) => {
  const data = await getItems(params.id);

  return (
    <Page title="Schalen">
      <VerticalMargin size="small">
        <PageHeader title={params.id} />
      </VerticalMargin>
      <MaxWidth>
        <ItemsForm items={data?.items} assesmentId={params.id} />
      </MaxWidth>
    </Page>
  );
};
small crownBOT
#

🔎 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)

small crownBOT
#
✅ Success!

This question has been marked as answered! If you have any other questions, feel free to create another post

Jump to answer

[Click here](#1234869760324272213 message)

tough ore
#

@twilit sedge Why is it working on my home page but not on the dynamic page? Im calling a 3rd party API btw

twilit sedge
small crownBOT
#
✅ Success!

This question's answer has been removed.

tough ore
#

Yes

twilit sedge
#

how does it "not work"? can you describe how it currently does in details?

#

what happens when you load the page

tough ore
#

So on localhost it just fetches but when I build it on vercel I nothing is happening. I see no fetch in the network tab either

twilit sedge
#

the network tab doesnt have the fetch because the fetch runs on the server not on the browser

tough ore
#

oh yea that makes sense 😅

twilit sedge
#

yeah so the more important thing is, how does it not work? error? or just a blank page? or what happened?

tough ore
#

No error, not a blank page but the items that suppose to show arent showing. It is showing in dev

twilit sedge
#

can add console.log(data) and head to vercel log to see what's the value of data

tough ore
#

where in vercel can I see that log?

twilit sedge
#

there is a Logs tab over here

tough ore
#

Ok I see the error now

#

thank you!