From cc5db2b37eeff948bf5a6f249e376a59830d6750 Mon Sep 17 00:00:00 2001 From: neodk2004 Date: Fri, 2 Jan 2026 14:55:56 +0100 Subject: [PATCH] feat: enable CORS and add frontend API test page --- backend/src/main.ts | 5 ++- frontend/app/test/page.tsx | 63 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 frontend/app/test/page.tsx diff --git a/backend/src/main.ts b/backend/src/main.ts index 438b2d9..034f88b 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -3,7 +3,10 @@ import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); - +app.enableCors({ + origin: 'http://localhost:3000', + credentials: true, + }); const port = process.env.PORT || 3001; await app.listen(port); diff --git a/frontend/app/test/page.tsx b/frontend/app/test/page.tsx new file mode 100644 index 0000000..8a0651d --- /dev/null +++ b/frontend/app/test/page.tsx @@ -0,0 +1,63 @@ +'use client'; + +import { useEffect } from 'react'; + +export default function TestPage() { + useEffect(() => { + console.log('--- FE TEST START ---'); + + // Feed testen + fetch('http://localhost:3001/feed') + .then(res => res.json()) + .then(data => { + console.log('FEED RESPONSE:', data); + }) + .catch(err => { + console.error('FEED ERROR:', err); + }); + + // Öffentliches Pet testen + fetch('http://localhost:3001/pets/2') + .then(async res => { + if (res.status === 403) { + console.log('PET 2: FORBIDDEN'); + return; + } + const data = await res.json(); + console.log('PET 2 RESPONSE:', data); + }) + .catch(err => { + console.error('PET 2 ERROR:', err); + }); + + // Followers-Pet testen (soll 403 geben) + fetch('http://localhost:3001/pets/5') + .then(async res => { + if (res.status === 403) { + console.log('PET 5: FORBIDDEN (expected)'); + return; + } + const data = await res.json(); + console.log('PET 5 RESPONSE:', data); + }) + .catch(err => { + console.error('PET 5 ERROR:', err); + }); + }, []); + + return ( +
+

🧪 Frontend API Test

+

+ Diese Seite dient nur zum Testen der Backend-APIs. +
+ 👉 Öffne die Browser-Konsole. +

+ +
+ ); +}