I have this express app in which I have routes file as:
import express from "express";
import { setNews } from "../controller/news-controller.js";
const route = express.Router();
route.get("/", (req, res) => res.send("Home Page Route"));
route.get("/news", setNews);
export default route;
and the news-controller is:
import News from '../modal/news.js';
export const setNews = async (req, res)=>{
try {
let data = await News.find({});
res.status(200).json(data);
} catch (error) {
res.status(500).json(error);
}
}
When I try these two routes locally, it works without any issue.
But when I tried hosting this using vercel.
Only / route is served if requested, it responds with "Home Page Route" which is obvious and /news is throwing 404 error
my vercel configuration in vercel.json:
{
"version": 2,
"builds": [
{
"src": "./index.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "./(.*)",
"dest": "/"
}
]
}