nitrojs / nitrojs/nitro

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

Open
#849 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement p2-nice-to-have route-rules v2
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

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
  • Would you be willing to help implement this feature?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the routeRules configuration shown in nitro.config.ts and trace how it produces dist/_headers during dev or build. Done means a missing leading slash is reported during that process, with behavior matching the agreed choice between an error and automatic correction.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.