Next.js Discord

Discord Forum

Nextjs13 app dir, sequentially running requests doesnt work during building process

Unanswered
Bartholomeas posted this in #help-forum
Open in Discord
Hello, as in title.
Im getting entire objects from that url (thats my individual api, not next route):
export const getKnowledgeBaseLandingArticles = async (): Promise<TPaginatedReturnType> => {
  const params = new URLSearchParams({
    Page: '1',
    Results: '3',
  })

  const url = `${API_URL}/knowledge-base/articles/published?${params.toString()}`
  try {
    const res = await fetch(url)

    if (!res.ok) {
      throw new Error('getKnowledgeBaseLandingArticles: response is invalid')
    }

    return (await res.json()) as TPaginatedReturnType
  } catch (err) {
    throw new Error(`getKnowledgeBaseLandingArticles: ${err}`)
  }
}


From that endpoint im getting array of objects like that:
[  {
    id: '70c0we4e5-e511-4b62-b739-fdf8e8305e96',
    title: 'title',
    shortDescription: ' shortdescrt.',
    createdAt: '2023-01-10T11:10:52.605937',
    categoryCode: 'Pigeons',
    category: { code: 'Pigeons', name: 'Gołebie' },
    thumbnailId: 'asd8asd8382d938d729348d79',
    isPublish: null
  }]


Then in this promise.all im sending request for every object to get image url from
thumbnailId
, this endpoint looks like that:
import { TApiFile } from 'api-pigener/other/documents/getFile'
import { API_URL } from 'misc/config/env'

export const getStaticFile = async (fileId: TApiFile['id']): Promise<TApiFile> => {
  if (!fileId)
    return Promise.reject(new Error('getStaticFile: fileId is undefined or null').message)

  try {
    const res = await fetch(`${API_URL}/documents/${fileId}`)

    if (!res.ok) {
      throw new Error('getStaticFile: response is invalid')
    }

    return res.json() as any
  } catch (err) {
    throw new Error(`getStaticFile: ${err}`)
  }
}

8 Replies

and from return im getting array of objects like that:
[  {
    id: '70c0we4e5-e511-4b62-b739-fdf8e8305e96',
    title: 'title',
    shortDescription: ' shortdescrt.',
    createdAt: '2023-01-10T11:10:52.605937',
    categoryCode: 'Pigeons',
    category: { code: 'Pigeons', name: 'Gołebie' },
    thumbnailId: ,
    isPublish: null
  }]
can you show the error log?
I do not get any errors :/
Im getting this during development:
Its correct url to my image
but wait a sec, ill send from build process to
and that during build