i have an express Api wrapped with server-less-http, on local everything works fine but after deployment the file route returns 404. i have server-less basePath set to “/”
const app = express();
app.use(express.json());
app.use(cookieParser());
app.use(cors(corsOptions));
app.use(userFiles)
app.use(register);
app.use(login);
app.use(validateCookie);
app.use(getUser);
app.use(updataUserProfile);
app.use(refreshCookie);
app.use(content);
app.use(getUsers);
const handler = serverless(app, {
binary: ["image/*"],
basePath: ["/"],
});
export default handler
Every other returns 200 just the route to serve static files returns 404, below is the route for static files
import { Router } from "express";
import express from "express";
const userFiles = Router();
userFiles.use("userFile/:image", express.static("userFiles"));
export default userFiles;
site
Github Repo
Why are you serving static files using Express? Netlify already serves static files.
I have a front end that makes requests to the express app to fetch images and other data mostly JSON format, all routes works fine expect the route to fetch images, on my local it works fine but after i deploy to netlify the route to fetch images returns 404 when i try using postman and when i inspect network on the live page it returns 502, i have no error log on my netlify, in regards to your question, my back end is built on Express and i used serverless-http to wrap it so i can deploy to netlify.
Fixed using Netlify redirect,
Added
[[redirects]]
from = "/userFIles/*"
to = "/userFiles/:splat"
status = 200
[[redirects]]
force = true
from = "/*"
status = 200
to = "/.netlify/functions/api/:splat"
to netlify.toml
Currently i have a problem uploading files, i get
ERROR Error: ENOENT: no such file or directory
i can see the folder in netlify Deploy file browser. i can’t understand why a folder is available after deployment and still don’t work. on local everything works fine and i don’t know how to go about it
Netlify is not a Node.js server. It doesn’t have your local filesystem. Refer to: How to Include Files in Netlify Serverless Functions