import { Book } from '@/books/Book';
import { NextPage } from 'next';
import Link from 'next/link';

async function getBooks(): Promise<Book[]> {
  const response = await fetch('http://localhost:3001/books');
  return response.json();
}

const BooksPage: NextPage = async () => {
  const books = await getBooks();

  return (
    <div>
      <h1>Bücher</h1>
      <ul>
        {books.map((book) => (
          <li key={book.id}>
            <Link href={`/books/${book.id}`}>{book.title}</Link>
          </li>
        ))}
      </ul>
    </div>
  );
};

export default BooksPage;

export const revalidate = 5 * 60; // 5 Minuten
