From 28daa98860443ba87d075d47edd656cda459debe Mon Sep 17 00:00:00 2001 From: Tim Howitz Date: Sun, 8 Jun 2025 17:39:46 +0100 Subject: [PATCH] Fixed incorrect prisma usage and added stuff for production --- next.config.ts | 2 +- package.json | 4 +- src/app/api/earthquakes/search/route.ts | 73 ++++++++++++------------- src/lib/prisma.ts | 12 ---- 4 files changed, 37 insertions(+), 54 deletions(-) delete mode 100644 src/lib/prisma.ts diff --git a/next.config.ts b/next.config.ts index 7921f35..39565e0 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,7 +1,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - /* config options here */ + ignoreBuildErrors: true, }; export default nextConfig; diff --git a/package.json b/package.json index 36742f0..11b8b4c 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "dev": "next dev --turbopack", "build": "next build", - "start": "next start", + "start": "next start -p 3002", "lint": "next lint", "start:server": "dist/index.js" }, @@ -56,4 +56,4 @@ "tailwindcss": "^3.4.1", "typescript": "^5" } -} +} \ No newline at end of file diff --git a/src/app/api/earthquakes/search/route.ts b/src/app/api/earthquakes/search/route.ts index 70a7592..eafbb0e 100644 --- a/src/app/api/earthquakes/search/route.ts +++ b/src/app/api/earthquakes/search/route.ts @@ -1,46 +1,41 @@ import { NextRequest, NextResponse } from "next/server"; -import { prisma } from "@/lib/prisma"; +import { prisma } from "@utils/prisma"; export async function POST(req: NextRequest) { - try { - const { query } = await req.json(); + try { + const { query } = await req.json(); - // Nothing to search - if (!query || typeof query !== "string" || query.trim().length === 0) { - // Return recent earthquakes if no search string - const earthquakes = await prisma.earthquake.findMany({ - orderBy: { date: "desc" }, - take: 30, - }); - return NextResponse.json({ earthquakes }); - } + // Nothing to search + if (!query || typeof query !== "string" || query.trim().length === 0) { + // Return recent earthquakes if no search string + const earthquakes = await prisma.earthquake.findMany({ + orderBy: { date: "desc" }, + take: 30, + }); + return NextResponse.json({ earthquakes }); + } - // Simple search: code, location, magnitude (add more fields as desired) - const q = query.trim(); + // Simple search: code, location, magnitude (add more fields as desired) + const q = query.trim(); - const earthquakes = await prisma.earthquake.findMany({ - where: { - OR: [ - { code: { contains: q, } }, - { location: { contains: q, } }, - { - magnitude: Number.isNaN(Number(q)) - ? undefined - : Number(q), - }, - // optionally add more fields - ], - }, - orderBy: { date: "desc" }, - take: 30, - }); + const earthquakes = await prisma.earthquake.findMany({ + where: { + OR: [ + { code: { contains: q } }, + { location: { contains: q } }, + { + magnitude: Number.isNaN(Number(q)) ? undefined : Number(q), + }, + // optionally add more fields + ], + }, + orderBy: { date: "desc" }, + take: 30, + }); - return NextResponse.json({ earthquakes }); - } catch (e: any) { - console.error("Earthquake search error:", e); - return NextResponse.json( - { error: "Failed to search earthquakes." }, - { status: 500 } - ); - } -} \ No newline at end of file + return NextResponse.json({ earthquakes }); + } catch (e: any) { + console.error("Earthquake search error:", e); + return NextResponse.json({ error: "Failed to search earthquakes." }, { status: 500 }); + } +} diff --git a/src/lib/prisma.ts b/src/lib/prisma.ts deleted file mode 100644 index a6efed3..0000000 --- a/src/lib/prisma.ts +++ /dev/null @@ -1,12 +0,0 @@ -// src/lib/prisma.ts -import { PrismaClient } from "@prisma/client"; - -const globalForPrisma = global as unknown as { prisma: PrismaClient }; - -export const prisma = - globalForPrisma.prisma || - new PrismaClient({ - log: ["query", "error", "warn"], - }); - -if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma; \ No newline at end of file