Next.js app with Python serverless functions #4023
-
I cannot for the life of me get Python serverless functions to work when trying to deploy a Next.js app. I have tried all three examples found in the official documentation (see here and here). A simplified version of my project layout is as follows: ├── pages If I deploy the project as-is the index page loads correctly but if I navigate to "/api/date" I get a 404 error. I can get the API endpoint to work by adding I'm really hoping there's something simple I've missed that will make me feel really dumb when it is explained to me. If you have any ideas where I went wrong I would appreciate your input. Additional notes:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hello, Next.js allows API routes in the framework itself. For that reason, it is not possible to use other languages than Node when using
Let me also clarify a few things:
That happens because you are opting-out of Zero Config. For that reason, you need to explicitly tell Now to also build your Next.js app:
The general recommendation is that you stay in Next.js territory and only deploy Node functions. Those will be under the umbrella of the framework and unlock all the official features available to you. Let us know how it goes. |
Beta Was this translation helpful? Give feedback.
-
This use case seems common. Most large websites write back-end code in a different language. It sounds like this design is not recommended, however. What is the recommendation from Vercel as to how to accomplish something like this? Should we create two separate deployments? |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, opening this discussion again to see if this solution also works with the app router? Has anyone tried it so far? |
Beta Was this translation helpful? Give feedback.
Hello,
Next.js allows API routes in the framework itself. For that reason, it is not possible to use other languages than Node when using
/pages/api
. One thing that you can try is to defer the API-side to Now itself, but be aware that you may lose a few functionalities:api/
.api/index.py
.pages/api/
, otherwise, you can have a few conflicts in routes.Let me also clarify a few things: