unjs / nitro

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

Throw warning for conflicting routeRules #1074

Open bencodezen opened 1 year ago

bencodezen commented 1 year ago

Describe the feature

⚠️ Problem

When a user configures their routeRules, it is currently possible to define conflicting routes that will break the intended build. For example:

{
  routesRules: {
    '/**': { swr: true }
  }
}

This seems straightforward at first, but if users are leveraging an /api route or other serverless functions that require a POST request, their build will ultimately fail.

💡 Proposed Solution

When the build detects that there will be some output that leverages APIs or serverless functions, there should probably be a warning (if not an actual failure) on the build because the distributed output will fail otherwise.

📝 Additional information

I'd be happy to help, but would probably need some pairing with a team member to get onboarded to the nitro engine and the team workflow.

danielroe commented 1 year ago

I think this seems like a good idea and if @pi0 agrees would be more than happy to chat about how this could be implemented.

pi0 commented 1 year ago

I like the idea of making some warnings, especially for wild card /** rules.

However, it is tricky when we exactly want to make such warning.

We might for example instead make a change to cache handler, bypassing POST requests fixing root cause of a cache on ** problem.