Vercel/NextJS: How to access serverless functions from frontend during local development?

My React/NextJS front end has a Button component that fetches data via a serverless function when the button is clicked. I want to test this functionality during local development with the Vercel dev/CLI tools, as manetioned here I am getting a 404 result when attempting to access my lambda functions. Here are the approximate steps that I’ve gone through so far:

  1. Create package.json with a dev script:

    "scripts": {
        "dev": "yarn codegen && next --hostname= --port=3001",
  2. Link to deployed vercel project

  3. Create vercel.json to specify builds and routes:

        "builds": [
            { "src": "*.html", "use": "@now/static" },
            { "src": "pages/api/*.py", "use": "@now/python" },
        "routes": [
            { "src": "/api/validate", "dest": "/pages/api/" }
  4. Create my test Lambda function (in python):

    from http.server import BaseHTTPRequestHandler
    from datetime import datetime
    class handler(BaseHTTPRequestHandler):
      def do_GET(self):
        self.send_header('Content-type', 'text/plain')
        self.wfile.write(str('%Y-%m-%d %H:%M:%S')).encode())
  5. Create my Button component:

            onClick={() => {
                    .then(response => { console.log(response)
                        response.json() })
                    .then(data => console.log(data))
            Generate sample dataset
  6. Run vercel dev

  7. Access website at localhost:3001 (next dev server address)

  8. Click button


I’m receiving a 404 response

Note: I can access the lambda function from localhost:3000/pages/api/ (vercel dev server address). This appears to manually kickstart the lambda function build and serve process. I thought that it should have been built and served already from the vercel.json specification and be available at localhost:3001/api/validate. This seems to agree with the Vercel documentation.

Note 2: Next dev/CLI tools build and serve javascript/typescript files just fine. I’m using python and Go functions as well, which are supported by Vercel dev/CLI but not Next