fix: Switch projects to Directus, add security fixes and example projects
All checks were successful
Production Deployment (Zero Downtime) / deploy-production (push) Successful in 14m27s

This commit is contained in:
2026-02-09 16:40:08 +01:00
parent b754af20e6
commit 4029cd660d
2 changed files with 195 additions and 46 deletions

View File

@@ -1,5 +1,5 @@
import { NextRequest, NextResponse } from 'next/server';
import { prisma } from '@/lib/prisma';
import { getProjects } from '@/lib/directus';
export async function GET(request: NextRequest) {
try {
@@ -7,56 +7,27 @@ export async function GET(request: NextRequest) {
const slug = searchParams.get('slug');
const search = searchParams.get('search');
const category = searchParams.get('category');
const locale = searchParams.get('locale') || 'en';
// Use Directus instead of Prisma
const projects = await getProjects(locale, {
featured: undefined,
published: true,
category: category && category !== 'All' ? category : undefined,
search: search || undefined,
});
if (!projects) {
// Directus not available or no projects found
return NextResponse.json({ projects: [] });
}
// Filter by slug if provided (since Directus query doesn't support slug filter directly)
if (slug) {
const project = await prisma.project.findFirst({
where: {
published: true,
slug,
},
orderBy: { createdAt: 'desc' },
});
const project = projects.find(p => p.slug === slug);
return NextResponse.json({ projects: project ? [project] : [] });
}
if (search) {
// General search
const projects = await prisma.project.findMany({
where: {
published: true,
OR: [
{ title: { contains: search, mode: 'insensitive' } },
{ description: { contains: search, mode: 'insensitive' } },
{ tags: { hasSome: [search] } },
{ content: { contains: search, mode: 'insensitive' } }
]
},
orderBy: { createdAt: 'desc' }
});
return NextResponse.json({ projects });
}
if (category && category !== 'All') {
// Filter by category
const projects = await prisma.project.findMany({
where: {
published: true,
category: category
},
orderBy: { createdAt: 'desc' }
});
return NextResponse.json({ projects });
}
// Return all published projects if no specific search
const projects = await prisma.project.findMany({
where: { published: true },
orderBy: { createdAt: 'desc' }
});
return NextResponse.json({ projects });
} catch (error) {
console.error('Error searching projects:', error);