Hello everyone,
I am trying to deploy the express serverless function along with the react app but it isn’t happening.
This is how I’ve initialized the serverless APIs. I’ve created a separate folder to install packages related to the server only.
Code of api.ts
import express, { Router } from 'express';
import serverless from 'serverless-http';
const api = express();
console.log('api', api);
const router = Router();
router.use('/', (req, res, next) => {
console.log('i am inside server');
next();
});
router.get('/hello', (req, res) => res.send('Hello World!'));
api.use('/api/', router);
export const handler = serverless(api);
These are all the folders I have.
Last is the netlify.toml
file
[build]
command = "npm run build"
functions = "netlify/functions/"
publish = "build"
[functions]
external_node_modules = ["express"]
node_bundler = "esbuild"
[[redirects]]
from = "/api/*"
to = "/.netlify/functions/:splat"
status = 200
force = true
After all this, I am still not able to access the API. For ref : GitHub - ardourApeX/netlify-serverless-function at feat/express