chore: add nextjs template

This commit is contained in:
Pranav Putta
2026-02-19 12:10:51 -08:00
parent 0283cf7ee7
commit a7675e42cd
18 changed files with 443 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
import { NextRequest, NextResponse } from "next/server";
import { Pool } from "pg";
const pool = new Pool({
host: process.env.DB_HOST || "127.0.0.1",
port: parseInt(process.env.DB_PORT || "5432"),
user: process.env.DB_USER || "myuser",
password: process.env.DB_PASSWORD || "mypassword",
database: process.env.DB_DATABASE || "mydb",
});
export async function GET(
request: NextRequest,
{ params }: { params: { id: string } }
) {
try {
const { id } = params;
const result = await pool.query(
`SELECT id, title, price_cents, slug, description
FROM products
WHERE id = $1`,
[id]
);
if (result.rows.length === 0) {
return NextResponse.json(
{ error: "Product not found" },
{ status: 404 }
);
}
return NextResponse.json(result.rows[0]);
} catch (error) {
console.error("Error fetching product:", error);
return NextResponse.json(
{ error: "Failed to fetch product" },
{ status: 500 }
);
}
}