#src/pages/api/auth

2 messages · Page 1 of 1 (latest)

tawdry surgeBOT
#

Hi @rain beacon. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

In Astro, routes are created automatically from the files in src/pages/ using file-based routing. There is no extra routing config. [Routing guide]

For API routes (“server endpoints”), the same rule applies: any .ts/.js file under src/pages becomes an endpoint whose URL matches its path. [Static file endpoints]

So for:

src/pages/api/auth/signin.ts
src/pages/api/auth/signout.ts
src/pages/api/auth/register.ts

Astro automatically exposes these as:

When the browser (or fetch()) makes a request to /api/auth/signin, Astro matches that URL to the file path under src/pages/ and calls the exported function for the HTTP method (GET, POST, etc.). [HTTP methods; Route priority]

So the request “knows” to go through pages/api/auth/... simply because of the URL path and Astro’s file-based routing convention.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: