Skip to content

getQuery() empty on Vercel #1020

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

Open
drewbaker opened this issue Apr 14, 2025 · 3 comments
Open

getQuery() empty on Vercel #1020

drewbaker opened this issue Apr 14, 2025 · 3 comments
Labels

Comments

@drewbaker
Copy link

drewbaker commented Apr 14, 2025

Environment

I have a Nuxt install, using the built in Nitro with some custom endpoints located in /server/routes/api. I am using defineCachedEventHandler for them.

Locally, getQuery() returns what you'd expect, but when deployed to Vercel, it's empty.

URL like this:
https://example.vercel.app/api/foo/e9cb0344-3bf3-44f6-8d90-c620a638be48/test?name=drew

Vercel logs the "searchParam" in it's logger, but I can't get getQuery() to return anything. I'm very perplexed.

Reproduction

export default defineCachedEventHandler(async (event) => {
    return getQuery(event)
},
{
    maxAge: 31_536_000 // 1 year
})

Describe the bug

getQuery() is empty on Vercel, but populated on local.

Additional context

Screenshot of the Vercel logs. Notice my console.log is all undefined, but the SearchParams are populated in this case with a test of writers=9).

Image
Image

Logs

@drewbaker drewbaker added the bug Something isn't working label Apr 14, 2025
@pi0 pi0 added nitro and removed bug Something isn't working labels Apr 15, 2025
@kricsleo
Copy link
Member

Cannot reproduce.

You may check this example as described here: https://github.com/kricsleo/repro-h3-1020/blob/main/server/routes/api/foo/%5Bpath%5D/test.ts

And the deployed API endpoint: https://repro-h3-1020.vercel.app/api/foo/e9cb0344-3bf3-44f6-8d90-c620a638be48/test?name=drew

It works fine, returning {"name":"drew"}.

Could you share more details? (A StackBlitz example or GitHub repo would be ideal) 🙏

@drewbaker
Copy link
Author

OK, so I figured this out. It was due to a Vercel and Nuxt (using Nitro) caching not playing well together:

    nitro: {
        // routeRules: {
        //     // All routes should be ISR
        //     '/**': {
        //         isr: true
        //     }
        // },
        prerender: {
            autoSubfolderIndex: true,
            crawlLinks: true
        }
    },

When the commented out code was on, getQuery() would be empty for any server route. Commenting out that code, and it would work. Super annoying bug to find.

@kricsleo
Copy link
Member

kricsleo commented Apr 17, 2025

Possibly related to nitrojs/nitro#1880

You may try this:

routeRules: {
    // "/**" won't work with ISR
    // '/**': {
    //     isr: true
    // },

    // "/*" works
    '/api/foo/*/test': {
      isr: true
    }
},

It's odd, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants