refactoed kafka ingestion to go via backend not web-db

This commit is contained in:
2025-11-13 17:42:04 +01:00
parent ba8c42e30e
commit 6a2c41bbdb
8 changed files with 147 additions and 38 deletions

View File

@@ -1,7 +1,8 @@
import { NextRequest, NextResponse } from 'next/server';
import { sendEvent } from '@/lib/kafka';
import type { EventBase } from '@/lib/events';
const BACKEND_URL = process.env.BACKEND_URL || 'http://localhost:5000';
export async function POST(req: NextRequest) {
try {
const body = await req.json();
@@ -16,7 +17,15 @@ export async function POST(req: NextRequest) {
ts: body.ts || new Date().toISOString(),
};
await sendEvent(event);
const res = await fetch(`${BACKEND_URL}/api/kafka/ingest`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(event),
});
if (!res.ok) {
throw new Error(`Backend returned ${res.status}`);
}
if (process.env.NEXT_PUBLIC_APP_ENV === 'dev') {
console.log('[ingest]', event);