Fixed incorrect prisma usage and added stuff for production

This commit is contained in:
Tim Howitz 2025-06-08 17:39:46 +01:00
parent a0f5a2f1de
commit 28daa98860
4 changed files with 37 additions and 54 deletions

View File

@ -1,7 +1,7 @@
import type { NextConfig } from "next"; import type { NextConfig } from "next";
const nextConfig: NextConfig = { const nextConfig: NextConfig = {
/* config options here */ ignoreBuildErrors: true,
}; };
export default nextConfig; export default nextConfig;

View File

@ -6,7 +6,7 @@
"scripts": { "scripts": {
"dev": "next dev --turbopack", "dev": "next dev --turbopack",
"build": "next build", "build": "next build",
"start": "next start", "start": "next start -p 3002",
"lint": "next lint", "lint": "next lint",
"start:server": "dist/index.js" "start:server": "dist/index.js"
}, },

View File

@ -1,5 +1,5 @@
import { NextRequest, NextResponse } from "next/server"; import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/prisma"; import { prisma } from "@utils/prisma";
export async function POST(req: NextRequest) { export async function POST(req: NextRequest) {
try { try {
@ -21,12 +21,10 @@ export async function POST(req: NextRequest) {
const earthquakes = await prisma.earthquake.findMany({ const earthquakes = await prisma.earthquake.findMany({
where: { where: {
OR: [ OR: [
{ code: { contains: q, } }, { code: { contains: q } },
{ location: { contains: q, } }, { location: { contains: q } },
{ {
magnitude: Number.isNaN(Number(q)) magnitude: Number.isNaN(Number(q)) ? undefined : Number(q),
? undefined
: Number(q),
}, },
// optionally add more fields // optionally add more fields
], ],
@ -38,9 +36,6 @@ export async function POST(req: NextRequest) {
return NextResponse.json({ earthquakes }); return NextResponse.json({ earthquakes });
} catch (e: any) { } catch (e: any) {
console.error("Earthquake search error:", e); console.error("Earthquake search error:", e);
return NextResponse.json( return NextResponse.json({ error: "Failed to search earthquakes." }, { status: 500 });
{ error: "Failed to search earthquakes." },
{ status: 500 }
);
} }
} }

View File

@ -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;