Fabis
Fabis

Reputation: 2062

Using Nuxt.js programmatically, but reusing the active Nuxt instance

can anyone point me in the right direction for using Nuxt.js programmatically inside a serverMiddleware?

XY: I want to run nuxt.renderRoute from inside a serverMiddleware that defines an API endpoint using Express. I can see examples in the docs (https://nuxtjs.org/docs/2.x/internals-glossary/nuxt-render/), but it looks like the loadNuxt method would start an entirely new Nuxt.js instance, wouldn't it? I want to re-use the Nuxt instance that already exists and is running the serverMiddlewares.

So to be clear - Nuxt.js is already up and running (who else would be running the serverMiddlewares?) so I just want to re-use that active instance to manually invoke renderRoute, instead of starting a new Nuxt instance.

Upvotes: 2

Views: 374

Answers (1)

Fabis
Fabis

Reputation: 2062

I figured it out. If you register the Express middleware with a Nuxt.js module, you can access the nuxt instance with this.nuxt inside the module.

Upvotes: 2

Related Questions