feat: enable CORS and add frontend API test page

This commit is contained in:
admin committed 2026-01-02 14:55:56 +01:00
1 parent 06e9240909
commit cc5db2b37e
2 files changed
+67 -1

No files matched your search

+4 -1
View File
@@ -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);
+63
View File
@@ -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 (
<section style={{ padding: '2rem' }}>
<h1>🧪 Frontend API Test</h1>
<p>
Diese Seite dient nur zum Testen der Backend-APIs.
<br />
👉 Öffne die <strong>Browser-Konsole</strong>.
</p>
<ul>
<li>Feed wird geladen</li>
<li>Pet 2 (public) wird geladen</li>
<li>Pet 5 (followers) sollte 403 sein</li>
</ul>
</section>
);
}