nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Show error during dev/build when routeRules are missing a leading slash

Open jschroeter opened this issue 2 years ago • 0 comments

Describe the feature

I spent hours on figuring out why my custom headers didn't work on Netlify. Then I realised the path needs to start with a slash otherwise it won't work on Netlify. Not sure about other providers.

So nitro.config.ts with

export default defineNitroConfig({
    preset: 'netlify',
    routeRules: {
        '_nuxt/**': { headers: { 'cache-control': 'max-age=31536000,immutable' } }
    }
})

does currently generate the following dist/_headers

_nuxt/*
  cache-control: max-age=31536000,immutable

which doesn't work.

Changing it to

routeRules: {
    '/_nuxt/**': { headers: { 'cache-control': 'max-age=31536000,immutable' } }
}

results in

/_nuxt/*
  cache-control: max-age=31536000,immutable

which works fine.

My suggestion is to print a console error if the path doesn't start with a slash. Or alternatively add the slash automatically. What do you think?

Additional information

  • [X] Would you be willing to help implement this feature?

jschroeter avatar Jan 18 '23 03:01 jschroeter