4

I'm trying to define a regex based dynamic path in Nuxt's serverMiddleware, but I'm not able to figure out how to achieve it because in the doc also there is no any mention about dynamic route.

I want to achieve something like this,

// ./nuxt.config.js
export default {
    modules: [
      ..
    ],
    serverMiddleware: [
        {
            path: '/sitemap/:filename(.*xml.gz)',
            handler: '~/api/serveSitemap.js'
        }
    ]  
}

And then get :filename param inside the handler..

//./api/serveSitemap.js
export default function(req, res) {
    filename = req.params.filename // is 'req.params' available in nodejs?
    // some code
    res.end()
}

Just to inform, I'm using Nuxtjs in SSR mode with Nodejs as a rendering server, and not using Expressjs. And this is the link which I'm referring for using Nuxt serverMiddleware: https://nuxtjs.org/api/configuration-servermiddleware/#custom-server-middleware

3
  • 1
    Did you solve this? Commented Sep 30, 2020 at 21:48
  • 1
    Did you solve this? Commented Dec 27, 2020 at 5:52
  • @ßiansor Sorry guys, I didn't find any solution for this problem yet, nor do I know the reason why it doesn't work. Just because of this shortcoming I had to change the approach towards my problem. Hope someone from Nuxt community helps to find the solution or at least some work around for this. Commented Dec 28, 2020 at 19:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.