I started with a full-stack app with Next.js and Typescript frontend, and a python backend. Since we wanted to deploy on vercel, we migrated all the backend functionality into typescript functions in the /api folder, accessible with:
fetch('api/**foldername**)
The problem is that I have a simple pytorch model so it needs to be python. I read online that you can have python serverless vercel functions too.
I need advice on how to make both serverless function types work together.
enter image description here
Here is my folder structure: app/api/routeName/route.ts
I tried the same with route.py, but that did not work. I also tried just putting upload.py in the api folder, but that also did not work.
Here is my upload.py file:
from http.server import BaseHTTPRequestHandler
class handler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.end_headers()
self.wfile.write("Hello, worldfbgdfgbdfgbd!".encode("utf-8"))
return
very simple just to test connectivity.
I tried using a fetch that console logs the response when a button on the frontend is clicked, and going to localhost:3000/api/update.
There isn’t much documentation online, and after looking at some example github repos im not sure why my case doesn’t work.
Any advice is very much appreciated.
Kyle Johnson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.