harden media
This commit is contained in:
38
apps/website/app/media/teams/[teamId]/logo/route.ts
Normal file
38
apps/website/app/media/teams/[teamId]/logo/route.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { teamId: string } }
|
||||
) {
|
||||
const { teamId } = params;
|
||||
|
||||
// In test environment, proxy to the mock API
|
||||
// In production, this would fetch from the actual API
|
||||
const apiBaseUrl = process.env.API_BASE_URL || 'http://localhost:3000';
|
||||
|
||||
try {
|
||||
const response = await fetch(`${apiBaseUrl}/media/teams/${teamId}/logo`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'image/png',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
// Return a fallback image or 404
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
|
||||
const buffer = await response.arrayBuffer();
|
||||
|
||||
return new NextResponse(buffer, {
|
||||
headers: {
|
||||
'Content-Type': 'image/png',
|
||||
'Cache-Control': 'public, max-age=3600',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching team logo:', error);
|
||||
return new NextResponse(null, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user