Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): normalize route rules with leading slash #2978

Merged
merged 6 commits into from
Jan 8, 2025

Conversation

gioboa
Copy link
Contributor

@gioboa gioboa commented Jan 7, 2025

πŸ”— Linked issue

Fixes: #2463

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Vercel deployment is failing because with this configuration πŸ‘‡ the .vercel/output/config.json is wrong.

//https://nitro.unjs.io/config
export default defineNitroConfig({
  compatibilityDate: "2025-01-07",
  srcDir: "server",
  routeRules: { "**": { headers: { "x-foo": "bar" } } },
  preset: 'vercel'
});

Forcing the initial / will solve the issue.

BEFORE ❌

FILE: .vercel/output/config.json

{
  "version": 3,
  "overrides": {},
  "routes": [
    {
      "headers": {
        "x-foo": "bar"
      },
      "src": "**"
    },
    {
      "handle": "filesystem"
    },
    {
      "src": "/(.*)",
      "dest": "/__nitro"
    }
  ]
}

AFTER βœ…

FILE: .vercel/output/config.json

{
  "version": 3,
  "overrides": {},
  "routes": [
    {
      "headers": {
        "x-foo": "bar"
      },
      "src": "/(.*)"
    },
    {
      "handle": "filesystem"
    },
    {
      "src": "/(.*)",
      "dest": "/__nitro"
    }
  ]
}

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@gioboa gioboa requested a review from pi0 as a code owner January 7, 2025 23:41
@pi0 pi0 changed the title fix: add / to routeRules path fix(config): normalize route rules with leading slash Jan 8, 2025
@pi0
Copy link
Member

pi0 commented Jan 8, 2025

Can you please also update test/fixture/nitro.config with one route rule without leading slash? πŸ™πŸΌ

@gioboa gioboa requested a review from pi0 January 8, 2025 09:03
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thnx!

@pi0 pi0 merged commit e9ec259 into nitrojs:v2 Jan 8, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants