Skip to content

Adding support for using python runtime and dynamic routes at the same time #28

Description

@codeXLinkX

As I answered in this issue vercel/next.js#56869, adding a custom runtime breaks the dynamic routes when the app is deployed to Vercel.

I found the below solution, in case anyone faces this problem.

Even though this Fast API example doesn't contain dynamic routes, it might still be useful to add { source: "/api/:path*", destination: "/api/:path*" } to the next config rewrites, like this:

const nextConfig = {
  rewrites: async () => {
    return [
      {
        source: "/api/py/:path*",
        destination:
          process.env.NODE_ENV === "development"
            ? "http://127.0.0.1:8000/api/py/:path*"
            : "/api/",
      },
      { source: "/api/:path*", destination: "/api/:path*" },
    ];
  },
};

This will ensure that the dynamic routes don't return 404 when the app is deployed to Vercel.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions