nuxt-community / redirect-module

No more cumbersome redirects for Nuxt 2!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get redirects from API without build everytime

liamjgm opened this issue · comments

/*
 ** Redirect module configuration
 */
redirect: async () => {
    const redirects = await axios.get(process.env.API_BASE_URL + '/application/redirects')
    return redirects.data
},

When my API response to get redirects changes and there are additional redirects. Is it possible update my redirects on nuxt without having to rebuild my app?

Nope, not really. An additional HTTP request before redirecting would hurt the perf of your page. But if you want to work on such a feature, feel free to send in a PR ☺️

Maybe add to vuex store?

@liamjgm Vuex isn't accessible when the module is called as it happens before Vue is initialized ☺️

@liamjgm you can create a custom server middleware
See https://nuxtjs.org/api/configuration-servermiddleware#custom-server-middleware

// example
import axios from 'axios'

export default function (req, res, next) {
  const redirects = await axios.get(process.env.API_BASE_URL + '/application/redirects')

  if (!redirects.data) {
    return next()
  }

  res.statusCode = 302
  res.setHeader('Location', redirects.data)
  res.end()
}

But as @manniL said, this can and will probably undermine the performance of your page

I think we can close this, I do not see an update that does not lose performance