Go functions don't seem to work correctly for wildcard routes

Given a Go function called /api/[...path].go, all requests like /api/login, /api/user, etc. are routed correctly and handled by the function.

Alas, all routes three levels deep (/api/user/verify, /api/shizzle/{id}) instantly return a 404. They do not even show up in the logs.

In that regard, it looks like the platform handles Go functions with a wildcard name [...path] as if it was named just [path].

This looks like a bug to me.

There’s another community post with 404 debugging tips that might be helpful. Please give these solutions a try and let us know how it goes.

A human should be around soon to offer more advice. But you can also get helpful information quickly by asking v0.

Thanks for reporting, I can reproduce this. I’ll share this internally

Thanks @jacobparis, please keep me updated about the status of this issue!

Hey @jacobparis, any update on this? Is there any known workaround we can use for the time being? Would a custom Docker-based runtime or something like this work?

Oh my, the solution is simply to use rewrites.

In my case, it was as simple as just renaming the function handler to /api/index.go and configuring this in vercel.json:

{
  "rewrites": [
    {
      "source": "/api/(.*)",
      "destination": "/api/index.go"
    }
  ]
}

Alas, the documentation is not very clear about this. I did not expect to be able to specify the filename of a function as destination, but apparently this works and the request still contains the originally requested path, so the request handler can correcly dispatch based on it.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.