0
0

Next.js チュートリアル Chapter6~

Posted at

Chapter6 Setting Up Your Database

chapter6

Route Handlers

Route Handlers allow you to create custom request handlers for a given route using Web Request and Response APIs.

Route Handlers are defined in a route.ts|js file inside the app directory.

export async function GET() {
  try {
    await client.sql`BEGIN`;
    await seedUsers();
    await seedCustomers();
    await seedInvoices();
    await seedRevenue();
    await client.sql`COMMIT`;

    return Response.json({ message: 'Database seeded successfully' });
  } catch (error) {
    await client.sql`ROLLBACK`;
    return Response.json({ error }, { status: 500 });
  }
}

localhost:3000/seedにgetリクエストが送られて、
上のgetメソッドが実行される。

Chapter7 Fetching Data

let's discuss the different ways you can fetch data for your application, and build out your dashboard overview page.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0