rust
rust copied to clipboard
Using along side nextjs in same project causes next pages/api routes to be ignored
I have a NextJS project that I have added rust api route to, however now all of the existing nextjs pages/api/** routes return a 404.
Here's what I've done:
- add Cargo and rust routes to
/api/
- added runtime to vercel.json
- swapped from using
next dev
tovercel dev
Everything (except for next api) works perfectly when I do this, including the rust api calls.
If I remove the rust runtime from vercel.json
then the nextjs api routes work as expected (but then the rust api won't work).
I continued down the rabbit hole started in #79 and discovered that the reason this is happening is that Vercel CLI proxies the nextjs commands to an inner next dev
process. When no additional routes are added, this proxy process works correctly. However once an API route exists, the CLI is adding a default 404 route to /api
that breaks the proxy and stops nextjs api routes from working.
https://github.com/vercel/vercel/blob/644b8a52cb2cc8f05e215e2230f95f902cdf8ae8/packages/fs-detectors/src/detect-builders.ts#L1041-L1050C8
If I disable the code referenced above, everything works correctly. I'm wondering if the nextjs config needs to have an ignoreRuntimes field added, but perhaps that is a hack. I don't really understand what its actual purpose is. Unfortunately there doesn't seem to be anything I can do to work around this issue without modifying the vercel CLI source.
So this seems to be an issue with vercel cli. Happy to raise an issue there instead, but is someone more familiar with this able to comment?