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!