Alternate Runtime for Serverless Function Issues

I am working with the Vercel Rust community runtime (repo here), and I am experiencing issues with local development identical to others in previous unresolved support threads:

I’m curious if anyone has further guidance on this, as things work perfectly fine when deployed, but it is impossible to develop locally using vercel dev, as the community runtime endpoints work but Next api routes return 404.

1 Like

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.

Hey, yes, I got it working.

You need to place your Next.js API routes inside of something different from api, like api-n.

Then, update vercel.json accordingly. In my case, the Go function is placed on the /api/server-lookup, so vercel.json looks like this:

{
    "$schema": "https://openapi.vercel.sh/vercel.json",
    "rewrites": [
        {
            "source": "/api/server-lookup",
            "destination": "/api/server-lookup"
        },
        {
            "source": "/api/:path*",
            "destination": "/api-n/:path*"
        }
    ]
}

I’ve also made the whole application easier to work with by updating the next.config.ts (when temporarily using next dev instead of vercel dev):

import type { NextConfig } from "next";
import { PHASE_DEVELOPMENT_SERVER } from "next/constants";

const nextConfig = async (
  phase: string,
  { defaultConfig }: { defaultConfig: NextConfig }
): Promise<NextConfig> => {

  const config: NextConfig =
    phase === PHASE_DEVELOPMENT_SERVER
      ? {
          rewrites: async () => {
            return [
              {
                source: "/api/:path*",
                destination: "/api-n/:path*",
              },
            ];
          },
        }
      : {};

  return {
    ...defaultConfig,
    ...config,
  };
};

export default nextConfig;

Hope it helps!