nitrojs / nitrojs/nitro

Allow glob pattern in routeRules

Open
#2,443 4 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement v3
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

Environment

nitro v2.9.6
node v22.0.0
npm v10.5.1

Reproduction

Try to create a redirect or something for certain type of files

Describe the bug

So this is what I have in my config:

routeRules: {
  '/somewhere.js': {
    redirect: '/somewhere-else',
  },
},

This works fine, when I visit "somewhere.js" I got redirected. But If I want it to make it global, like this:

routeRules: {
  '/**.js': {
    redirect: '/somewhere-else',
  },
},

It simply doesn't work. What I tried: /**.js, /*.js, **.js, *.js, **/**.js. I also tried to add \ and \\ in front of the dot, but same results.

What kind of glob is used in the pattern? I didn't find in the docs information how to make custom routes for assets.

Additional context

No response

Logs

No response

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 by tracing how the routeRules configuration matches request paths in Nitro, using the single-file redirect example as the baseline. Reproduce the configuration with a wildcard JavaScript pattern and verify that matching paths redirect as expected, then add or update coverage for the supported glob syntax.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.