Can't reach function endpoint using Express and Netlify functions - Cannot GET /api/badFunc/fulfilled

Site URL: https://expressfunctions.netlify.app

Test repo URL: https://github.com/justsilencia/test

I’m trying to use Express within a Netlify function to setup a few routes that perform different tasks. I have two functions currently in the test repo: goodFunc and badFunc

goodFunc is a basic Netlify function, and it works fine when I tag the endpoint using Postman.

badFunc uses Express with a single route named fulfilled. It will not let me reach this endpoint, and I get the the following error in Postman:

Cannot GET /api/badFunc/fulfilled

Code for badFunc

import express, { Router } from "express";
import serverless from "serverless-http";

export async function handler(event, context) {
    const api = express();
    const router = Router();
  
    router.get('/fulfilled', (req, res) => res.status(200).json({ "work": "Lets go"}));
  
    api.use('/api/', router);
  
    return serverless(api)(event, context);
  }

netlify.toml

[build]
  base = "/"
  command = "npm run build"
  publish = "/"

[functions]
  directory = "functions"

[[redirects]]
  from = "/api/*"
  to = "/.netlify/functions/:splat"
  status = 200

I’m using the following URL in Postman to get the error:

https://expressfunctions.netlify.app/api/badFunc/fulfilled

I’m almost positive that Postman is reaching the endpoint because it will error out if I have a syntax error in badFunc. However, I just can’t obtain a successful response.

Help would be GREATLY appreciated. Thanks you!

Have you tried following the Express on Netlify documentation?

Yes… My code is almost an exact replica of the code in that article…

@justsilencia I noticed the similarity, but I asked because there are differences.

So I suppose to rephrase, have you tried with exactly the code in the documentation?

Just so that as with your existing goodFunc test, you can confirm if it works for you, and have yet another baseline to compare to.

I did start with the exact code from that article. I just now went back and tried it again to be sure, and got the same error. After trying many variation of code, I just settled on my current version.

It’s very strange… I’m sure I’m missing something quite simple.

So to confirm, following the documentation, without changes, results in a function that doesn’t work?

No. It works. I had an issue with getting the build to work with exact code, so I made a few changes that allowed the build to succeed. This must have thrown off the routing somehow. Thanks for nudging me back toward the correct path.

https://github.com/justsilencia/replica

https://docreplica.netlify.app

Based on your repo, the hello endpoint seems to be working: docreplica.netlify.app/api/hello