Swadhin Biswas feat(api): add runner, analytics, packages, and security services · 3/6/2026
28f7954
23 lines · 640 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
 * CSRF Token Endpoint
 * Returns a CSRF token and sets the corresponding cookie.
 * Frontend should call GET /api/auth/csrf-token before making state-changing requests,
 * then include the token as X-CSRF-Token header.
 */

import { getCsrfToken } from "@/middleware/csrf";
import type { APIRoute } from "astro";

export const GET: APIRoute = async ({ request }) => {
  const { token, cookie } = getCsrfToken(request);

  return new Response(JSON.stringify({ csrfToken: token }), {
    status: 200,
    headers: {
      "Content-Type": "application/json",
      "Set-Cookie": cookie,
      "Cache-Control": "no-store",
    },
  });
};