Skip to content

Commit

Permalink
added small logic to test in any env
Browse files Browse the repository at this point in the history
  • Loading branch information
ashucoder9 committed Sep 9, 2024
1 parent 25b3a92 commit 9d7cfb1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/api/generate-certificate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export async function POST(req: NextRequest) {
const { courseId, userName } = await req.json();
if (!courseId || !userName) { return NextResponse.json({ error: 'Missing required fields' }, { status: 400 }); }
const courseName = getCourseName(courseId);
const templateUrl = 'http://localhost:3000/certificates/AvalancheAcademy_Certificate.pdf';
const protocol = req.headers.get('x-forwarded-proto') || 'http';
const host = req.headers.get('host') || 'localhost:3000';
const serverUrl = `${protocol}://${host}`;
const templateUrl = `${serverUrl}/certificates/AvalancheAcademy_Certificate.pdf`;
const templateResponse = await fetch(templateUrl);

if (!templateResponse.ok) { throw new Error(`Failed to fetch template`); }
Expand Down

0 comments on commit 9d7cfb1

Please sign in to comment.