nitrojs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.build
MIT License
6.31k stars 521 forks source link

Allow glob pattern in routeRules #2443

Open krehak opened 6 months ago

krehak commented 6 months ago

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

reslear commented 3 weeks ago

also have a problem with -3 symbs

https://github.com/nitrojs/nitro/blob/1cc357fd76dc538a1dab468a13daaf7ab447c427/src/core/config/resolvers/route-rules.ts#L39

redirect to root route:

instead '/demos/**': { redirect: { statusCode: 301, to: '/**' } }

need write '/demos/**': { redirect: { statusCode: 301, to: '//**' } }

pi0 commented 3 weeks ago

@krehak This feature (to allow mixing dynamic */** and static .js in the same segment (after last /) will be available in Nitro v3 only based on rou3 new feature, due to internal changes, we cannot have it in Nitro v2.

dear @reslear please feel free to report on a new issue with runnable reproduction.