Back to Posts

Fix Error 429 When Using Nuxt 3 Static Site Generator

While converting this site from a standard Vue 3 site to Nuxt 3, I ran into issues of missing pages, 429's and finally a confusing 500 which prevented prerendering and even generation of the site.

To begin with, I had deployed the page but noticed weird rendering behaviour. Two distinct issues arose. First, when I shared a link, the fetched URL no longer rendered the page title or lead image in chat apps that supported it. Secondly, loading a post directly threw a 404 but still rendered the post.

Digging into the first problem, I started looking at my existing redirects () as well as my build logs to look for errors. I ran back through the recommended configurations for my stack of Nuxt 3, Netlify hosting, and content run through Hygraph. Eventually I removed my old redirects as I didn't think they were necessary for Nuxt SSG sites. I finally looked more at the generated content and finally caught that the post pages hadn't rendered. Around this time I remembered using <ClientOnly> to prevent a hydration missmatch on the component that rendered lists of posts.

After resolving the original or 70th reason why I had wrapped those links in <ClientOnly>, I was inundated with 429's, which you'll remember means "Too Many Requests". With this new clue, I looked into throttling Nuxt's generate command so that it would stop hitting my resources too often.

With this new focus, I located Hygraph's Nuxt Rate Limit recommendation! Awesome. This little bit of code needs to be added to Nuxt's Nitro devserver config. Previously it was a part of the Renderer key. With some tweaks to make it run slow enough, I was able to get past the 429's to encounter the final issue: 1 eassssy 500.

This final issue was related to encoded slashes in a url slug. I had two similar titles that contained GD/GG encoded as GD%2FGG. In the end I decided to replace the encoded slashes with a dash to match similar URLs, eg GD-GG. AFAIK, they sh

To recap, my mistakes were:

  • Left the old /* /index.html .200
  • Assumed all of my posts were caught by the default crawling config for Nuxt Generate
  • Rate Limited by Hygraph
  • Special characters in post URL slugs were breaking Nuxt generat

Fix 429 errors on Nuxt Generate

If you came here looking for issues related to 429's when generating your website, you will need to update your Nuxt configuration for concurrency and interval like so, adjusting the values depending on your resource's limits.

// nuxt.config.ts
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  // your config overrides
  nitro: {
    prerender: {
      concurrency: 4,
      interval: 500,
    },
  },
});

This configuration used to be at the root of the configuration under prerender but it is now located in the Nitro configuration.

© 2024