import type { APIRoute } from 'astro';
import { storage } from '../../lib/storage';

export const prerender = false;

export const GET: APIRoute = async () => {
  try {
    const tags = await storage.getAllTags();

    return new Response(JSON.stringify(tags), {
      status: 200,
      headers: {
        'Content-Type': 'application/json',
      },
    });
  } catch (error) {
    console.error('Error in GET /api/tags:', error);
    return new Response(JSON.stringify({ error: 'Failed to read tags' }), {
      status: 500,
      headers: {
        'Content-Type': 'application/json',
      },
    });
  }
};
