tezvyn:

Nuxt Server Routes: Your Backend in a Folder

Source: nuxt.comintermediate

Nuxt Server Routes let you build a backend inside your frontend project. Create API endpoints by adding files to the `server/api` directory, which automatically get an `/api` prefix. The common footgun is forgetting this prefix difference with `server/routes`.

Nuxt Server Routes let you build a backend inside your frontend project, with files mapping directly to endpoints. Create API endpoints by adding files to `server/api` (e.g., `hello.ts` becomes `/api/hello`). For routes without the `/api` prefix, use the `server/routes` directory. Nuxt also supports server middleware for tasks like logging or auth that run on every request. The main footgun is forgetting the path difference: `server/api` routes are prefixed with `/api`, but `server/routes` are not, often causing 404s.

Read the original → nuxt.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Nuxt Server Routes: Your Backend in a Folder · Tezvyn