NuxtN
Nuxt11mo ago
102 replies
Samuelreichoer

Prerendering not working

Hi, I use nuxt with ddev and craft cms. So basically I run ddev npm run dev for starting the dev server -> Nuxt runs in docker on that url http://0.0.0.0:3000 and gets proxied by the nginx server. Therefor I am able to see the frontend on https://craft-nuxt-starter.ddev.site. When using the dev mode or build script I see no error and data fetching from the https://craft-nuxt-starter.ddev.site/v1/api/xxxx works perfectly.

My nuxt config looks like that:

export default defineNuxtConfig({
  devServer: {
    host: '0.0.0.0',
    port: 3000,
  },
  hooks: {
    async 'prerender:routes'(ctx) {
      const resp = await fetch('https://craft-nuxt-starter.ddev.site/v1/api/queryApi/allRoutes?siteIds=%5B1%2C2%2C3%5D').then(
        res => res.json(),
      )
      for (const page of resp) {
        const formatedPage = page.replace(process.env.NUXT_PRIMARY_SITE_URL, '')
        ctx.routes.add(formatedPage)
      }
    },
  },
})


But when I try to generate the site it throws following errors for every page:

  ├─ /es/noticias/fat-cat (271ms)                                                                                                                                                                nitro 2:14:59 PM
  │ └── [500] 


The fetch from the prerender hook works but the api calls in the pages to get the data not.
Was this page helpful?