Can’t Call API Route After Deployment (Works in Development)

I’m using Nuxt 3 and deploying my project on Netlify. My API route (subscribe.ts) works perfectly in development, but after deployment to Netlify, it returns a 404 error.

Calling the api route

 const response = await $fetch('/api/subscribe', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: { email: email.value }
    })

Site name: fineprint.netlify.app
build.zip (5.5 KB)

What I can see there is only the search.json, but no subscribe.ts

5:15:35 PM: [info] [nitro] Prerendering 6 initial routes with crawler
5:15:35 PM: [log] [nitro]   ├─ /__studio.json (11ms)
5:15:35 PM: [log] [nitro]   ├─ /200.html (74ms)
5:15:35 PM: [log] [nitro]   ├─ /404.html (74ms)
5:15:36 PM: [log] [nitro]   ├─ /api/search.json (424ms)
5:15:36 PM: [log] [nitro]   ├─ /api/_content/cache.1739452505464.json (489ms)
5:15:36 PM: [log] [nitro]   ├─ / (616ms)
5:15:36 PM: [log] [nitro]   ├─ /_payload.json?7a2c168b-cf08-4a1e-9cac-b482ea0512fa (78ms) (skipped)
5:15:36 PM: [log] [nitro]   ├─ /_payload.json (78ms)
5:15:36 PM: [log] [nitro]   ├─ /api/_content/navigation/i5pZc4XEtQ.1739452505464.json (85ms)
5:15:36 PM: [log] [nitro]   ├─ /api/_content/query/ndwoyw5i9L.1739452505464.json (271ms)
5:15:36 PM: [log] [nitro]   ├─ /api/_content/query/8gqiU2KnmM.1739452505464.json (272ms)

It worked now, had to use npm run build

1 Like