Garmaine Staff asked 1 year ago

Strapi is a amazing platform for headless cms. However, i've been using Nuxt.js with SSR for a long time with Express. Now, i'm thinking about switch to Strapi to use it as a cms and API builder. I read that Nuxt.js can be used as middleware for Koa, and i tried use itdo that but without a success.

This is my code:

My code for nuxt middleware: (middlewares/nuxt/index.js)

const { Nuxt, Builder } = require('nuxt')


module.exports = strapi => {
  return {

  async initialize() {

    const nuxt = new Nuxt()

    // Build in development
      const builder = new Builder(nuxt)
      await builder.build()


    strapi.app.use(async (ctx, next) => {
      console.log(ctx)

      ctx.status = 200
      ctx.respond = false // Mark request as handled for Koa
      ctx.req.ctx = ctx // This might be useful later on, e.g. in nuxtServerInit or with nuxt-stash
      await nuxt.render(ctx.req, ctx.res)
    })
  }
  }
};

my config/middleware.json

{
  "timeout": 100000,
  "load": {
    "before": [
      "responseTime",
      "logger",
      "cors",
      "responses",
      "gzip",
      "nuxt"
        ],
    "order": [

    ],
    "after": [
      "parser",
      "router",
      "public"
        ]
  }
}

When i use the settings above Nuxt.js work fine with no errors. Nevertheless using the same settings above i can't acces the Strapi admin panel or any else API built with Strapi.

I suspect the problem is with the router middleware, it doesn't call next().

Thanks in advance