Next.js Discord

Discord Forum

routes with multiple runtimes in a project

Unanswered
Red Crossbill posted this in #help-forum
Open in Discord
Red CrossbillOP
Hello I am trying to serve endpoints via serverless functions using python and typescript in the same project.
Individually they work great but when deployed together the functions are getting deployed but the endpoint routes are being overwrriten and not working.

Here is the structure

- api/index.py route served by python is active
- pages/api/index.ts is not working (serverless function is deployed) but the route is inactive. Getting a 404
- app/api/index route served by an edge function is deployed and working

This is the rewrites section in next.config.js
 return [
      {
        source: "/api/python/task/:path*",
        destination:
          process.env.NODE_ENV === "development"
            ? "http://127.0.0.1:8000/api/python/task/:path*"
            : "/api/python/task/",
      },
    ];

The only paths that work are the edge functions. Can anyone point out how to surface out the endpoints served by typescript functions?

20 Replies

Red CrossbillOP
You mean for the typescript functions?
If I remove the python functions the typescript routes are working fine
migrate pages/api/index.ts and app/api/index/route.ts to the root /api. afaik the root /api will override your pages/api routes and route handlers
so you can't have
api/foo.py
pages/api/bar.ts

but you can have
api/foo.py
api/bar.ts
Red CrossbillOP
hmm so this is only for pages/api ? Because app/api/healthz/route.ts seems to be working fine
@Red Crossbill hmm so this is only for `pages/api` ? Because `app/api/healthz/route.ts` seems to be working fine
does it still work fine if you change it to nodejs runtime?
i think vercel bundle the edge endpoints separately and other endpoints (nodejs/py/go/etc.) separately
Red CrossbillOP
work fine = they are getting deployed fine( both python and typescript) but I can't hit the typescript endpoints. So they aren't technically reachable but they are getting deployed
which means they don't work fine, do they?
thing is, one thing is overwriting the other. the build process builds both, but only one gets deployed
Red CrossbillOP
This is also kinda not working unless I misconfigured something here but not able to serve these both 😦
api/foo.py
api/bar.ts
Is there anything specific to configure on the routes ?
.py is working but not the .ts
Any help is greatly appreciated 🙏
interesting, it used to work for me before :thinkies:
@Red Crossbill This is also kinda not working unless I misconfigured something here but not able to serve these both 😦 api/foo.py api/bar.ts
this works normally, i didnt set up typescript but it should be the exact same
Red CrossbillOP
thank you for the check .. I 'll give it a try again .. can't seem to make this work with typescript
Red CrossbillOP
Ok I managed to create a sample project. https://github.com/pavan4/python-node-vercel If you add typescript and there is tsconfig.json in the folder then the serverless fucntions are crashing. the exact error is
Error: Unexpected token 'export'

When I do deploy locally I get this warning :

WARN! When using Next.js, it is recommended to place JavaScript Functions inside of the `pages/api` (provided by Next.js) directory instead of `api` (provided by Vercel). Other languages (Python, Go, etc) should still go in the `api` directory.
Learn More: https://nextjs.org/docs/api-routes/introduction

I did a test deploy here to : https://test-kappa-five-80.vercel.app/api/foobar