RSS feed

I was so busy setting up the site backend that I forgot to generate an RSS feed for it. (Thanks, @rectangular, for the reminder). Surprisingly, or maybe not surprisingly, this wasn’t easy. After realizing I couldn’t create the RSS feed using a template in Nuxt, I installed @nuxt/feed, which automatically generates the feed by setting a handful of options and an async function in the nuxt.config.js file.

Since I’d need to fetch entries from Contentful in the async function, I refactored the plugin, so I could require the relative file in the config file. This worked in local dev, but crashed my site on Now. After an hour of troubleshooting and research, I realized that when Now converts the site to serverless, it doesn’t carry over any files besides the config file and those generated in the public folder—you have to specify which server files to include by adding { "serverFiles": ["plugins/**"] } to the now.json file’s builds object.

Okay. This worked, but now my RSS feed wouldn’t display any entries. At first, I thought this might be another access token issue, but the undefined environment variable I referenced in the feed clued me to revisit env vars. It turns out Now has two spots to list environment variables in the now.json file—a top-level env object and another one at build.env. All my variables were set on build.env, which only exposes these variables during the build phase, not runtime—makes sense. Listing them in the top-level env objects exposes them for both build and runtime.

Now, I have a working RSS feed, but still don’t have routes for individual articles, so those links in the feed currently 404. I’ll hook that up next.