Skip to content

Commit

Permalink
Use a route handler for the PDF rendering. (#509)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhemphill authored Jun 8, 2024
1 parent f8ed4b0 commit 15e1a4c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 31 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.0.2] - 2024-06-08

### Changed

- Switch to using a route handler for PDF rendering
- The `/pages` folder is finally gone 🎉

## [5.0.1] - 2024-06-08

### Changed
Expand Down
1 change: 0 additions & 1 deletion next-env.d.ts
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.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nextjs-resume",
"version": "5.0.1",
"version": "5.0.2",
"type": "module",
"author": {
"name": "Colin Hemphill",
Expand Down
29 changes: 29 additions & 0 deletions src/app/api/pdf/route.tsx
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',
},
});
}
29 changes: 0 additions & 29 deletions src/pages/api/pdf.tsx

This file was deleted.

0 comments on commit 15e1a4c

Please sign in to comment.