I'm building an application that allows a user to render an RSS feed from a Firestore Collection. My solution is to use a Nuxt Server Route that returns with an XML file rendered via an RSS feed generator.
The issue that arises is that I cannot for the life of me figure out how to access Firestore within a Server Route. The documentation for VueFire, the handler I'm using to interface with Firebase, states
"You don't need to do anything special to make it work with SSR, everything is handled automatically."
This simple line has done nothing but vex me, as any of the usual methods of accessing Firestore (useFirestore(), getCurrentUser(), being two examples), fails with a (app/no-options) error.
Here's an example of the code that's failing. I'm basing this code off of the Middleware Example in the VueFire documentation.
// server/routes/[user]/rss.js
import { useFirestore } from 'vuefire'
export default defineEventHandler(async event => {
const db = await useFirestore();
})
What am I missing here? Why does VueFire fail to initialize in server routes and server routes only? Thanks.
Things I've Tried:
- I used the knowledge from this repo to ensure SSR was enabled correctly
- I explored multiple guides for utilizing SSR with Nuxt 3, but all of these on Stack Overflow and beyond ignore the Server Routes system
My final solution will be manually importing Firebase Admin, but that seems counterintuitive to the sentence "You don't need to do anything special to make it work with SSR"