nuxt-community / netlify-files-module

Nuxt 2 module to create new _headers, _redirects and netlify.toml files for Netlify or to use existing ones
MIT License
50 stars 5 forks source link

How to use this module? #14

Closed rinseringma closed 4 years ago

rinseringma commented 4 years ago

I've read the documentation on the github page, but I can't figure out how to use this module to create an _redirect file for Netlify.

What I want is that it would generate that file and write it to the static folder. Redirects must be pulled from an custom API endpoint containing the old url, new url and a statuscode. So that the marketeers can adjust the redirects in the backend according to their needs.

Could someone help me setting this up? Thanks!

andre-brdoch commented 4 years ago

currently the _redirects file can not be generated dynamically with this module. However, Netlify allows to configure redirects also via netlify.toml, which you can generate with this module like this:

// nuxt.config.js
export default {
  buildModules: [
    '@nuxtjs/netlify-files'
  ],
  netlifyFiles: {
    netlifyToml: {
      redirects: [
        {
          from: '/old',
          to: '/new',
          status: 302
        }
      ]
    },
    // if no other netlify files are needed, you can set this to false
    // copyExistingFiles: false
  }
}
manniL commented 4 years ago

Published the recent version now as well 👍🏻 So programmatic creation is available now ☺️