-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a route handler for the PDF rendering. (#509)
- Loading branch information
1 parent
f8ed4b0
commit 15e1a4c
Showing
5 changed files
with
37 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
/// <reference types="next/navigation-types/compat/navigation" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { allPrivateFields } from '@content'; | ||
import { renderToBuffer } from '@react-pdf/renderer'; | ||
import { NextResponse } from 'next/server'; | ||
import PDF from 'src/components/PDF/PDF'; | ||
|
||
const privateKey = process.env.PRIVATE_KEY; | ||
|
||
export async function GET(request: Request) { | ||
const { searchParams } = new URL(request.url); | ||
const secret = searchParams.get('secret'); | ||
|
||
let privateInformation; | ||
if (secret !== null) { | ||
if (secret !== privateKey) { | ||
return new NextResponse('Not authorized', { status: 401 }); | ||
} | ||
privateInformation = allPrivateFields; | ||
} | ||
|
||
const pdfStream = await renderToBuffer( | ||
<PDF privateInformation={privateInformation} />, | ||
); | ||
|
||
return new NextResponse(pdfStream, { | ||
headers: { | ||
'Content-Type': 'application/pdf', | ||
}, | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.