Last active
February 27, 2025 07:07
-
-
Save 03balogun/8f69cc2754c163fd1305ed2da2f5360c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // app/api/report/route.ts | |
| import {ErrorReport, Report} from "@/components/reports/Report"; // Import components | |
| export async function GET(req: NextRequest) { | |
| const response = await makeAPIRequestToTheBackend() | |
| const component = response?.status | |
| ? Report({record: response?.data}) | |
| : ErrorReport({message: response?.message || 'An error occurred generating your report'}) | |
| const stream = (await renderToStream(component)) as unknown as ReadableStream; | |
| const blob = await new Response(stream).blob(); | |
| const name = `expenseai-report-${Date.now()?.toString()}` | |
| const headers = { | |
| "Content-Type": "application/pdf", | |
| "Cache-Control": "no-store, max-age=0", | |
| "Content-Disposition": `inline; filename=${name}.pdf` | |
| } | |
| return new Response(blob, { | |
| headers | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment