Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Next.js API Routes work on development but 404 on production

In my next.js website, I have an api endpoint at /pages/api/views/[slug].js, which fetches the amount of views from a database (supabase) of each of my blogs. The setup works fine in my development server, (npm run dev), but when I deploy the app to production, all the API calls to the /pages/api/views/[slug].js endpoint return 404, saying that there is no page there.

I have set env variables in vercel's dashboard.

Additionally, when I try calling the default /pages/api/hello endpoint, I also get a 404 error.

Production website: https://www.ganning.me/blog

GitHub Repo: https://github.com/ganning127/ganning.me

hello.js

// Next.js API route support: https://nextjs.org/docs/api-routes/introduction

export default function handler(req, res) {
  res.status(200).json({ name: 'John Doe' })
}
like image 788
Ganning Xu Avatar asked Jan 30 '26 08:01

Ganning Xu


1 Answers

/pages/api/hello

Please remove pages from url then try it will work.(/api/hello)

like image 175
Muhammad zeshan Avatar answered Feb 01 '26 00:02

Muhammad zeshan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!