Skip to content

SvelteKit and Nuxt server endpoints are on the map - #138

Open
ryoaonetsuki wants to merge 6 commits into
haydenschmitty:mainfrom
ryoaonetsuki:feat/sveltekit-nuxt-server-routes
Open

ryoaonetsuki wants to merge 6 commits into
haydenschmitty:mainfrom
ryoaonetsuki:feat/sveltekit-nuxt-server-routes

Conversation

@ryoaonetsuki

Copy link
Copy Markdown

Problem

A SvelteKit +server.ts and a Nuxt file under server/api/ or server/routes/ answer a URL by where they sit in the folder, but the map showed none of them, so the website's requests to them weren't connected:

  • src/routes/api/items/+server.ts with export async function GET() — no endpoint at all
  • server/api/items/[id].ts with defineEventHandler(…) — no endpoint at all

Change

  • SvelteKit: a +server.ts now yields one endpoint per exported method (GET, POST, …), at the URL of its folder. Route groups (…) and parallel slots @… are skipped, [param] becomes :param, [...rest] becomes *, and [[optional]] becomes :param.
  • Nuxt: a file under server/api/ yields /api/…, under server/routes/ the plain URL; the method comes from a .get. / .post. suffix on the file name (or ANY without one), index means the folder itself, and the same [param] / [...rest] rules apply. Only files that actually call defineEventHandler (or defineCachedEventHandler / defineLazyEventHandler) are read, so a plain server/api/ folder in a non-Nuxt project is left alone.

Note: these new endpoints are now judged by Health like Next.js route handlers are — a route nothing calls shows as unused, which is the honest read for a dead endpoint.

How I tested

  • New tests/server-routes.test.mjs: 6 tests — one endpoint per exported method, groups / rest / optional segments, a +server with no methods, Nuxt method suffixes and index, server/routes, the defineEventHandler gate, and an end-to-end test where both kinds land on the map and the website's fetches connect to them. All 6 fail on the code before this change and pass with it.
  • Full suite: npm test — 490 of 494 tests pass. The 2 failures are pre-existing timing-threshold tests (C# and Liquid pattern-matching speed) that also fail on the code before this change (the 4 failures are pre-existing timing failures on this slow machine, unchanged from before this change).
  • Tried on small sample SvelteKit and Nuxt projects.

Tested on Linux only. claude plugin validate was not available on this machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant