Skip to content

Commit ef85162

Browse files
committed
Fix payload too large error - increase JSON limit and handle base64 data URLs
1 parent 9f2ab60 commit ef85162

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

backend/src/server.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ app.use(cors({
7777
// Webhook routes need raw body
7878
app.use('/api/webhooks', express.raw({ type: 'application/json' }));
7979

80-
// Regular JSON parsing for other routes
81-
app.use(express.json());
82-
app.use(express.urlencoded({ extended: true }));
80+
// Regular JSON parsing for other routes - increased limit for certificate data URLs
81+
app.use(express.json({ limit: '50mb' }));
82+
app.use(express.urlencoded({ extended: true, limit: '50mb' }));
8383
app.use(limiter);
8484

8585
// Serve uploaded files

backend/src/services/certificate.service.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,21 @@ import fetch from 'node-fetch';
33

44
export const generateCertificate = async (templateUrl, mapping, data) => {
55
try {
6-
// 1. Fetch the template
7-
const existingPdfBytes = await fetch(templateUrl).then(res => res.arrayBuffer());
6+
// 1. Fetch the template - handle both URLs and base64 data URLs
7+
let existingPdfBytes;
8+
9+
if (templateUrl.startsWith('data:')) {
10+
// Handle base64 data URL
11+
const base64Data = templateUrl.split(',')[1];
12+
existingPdfBytes = Buffer.from(base64Data, 'base64');
13+
} else {
14+
// Handle regular URL
15+
const response = await fetch(templateUrl);
16+
if (!response.ok) {
17+
throw new Error(`Failed to fetch template: ${response.status} ${response.statusText}`);
18+
}
19+
existingPdfBytes = await response.arrayBuffer();
20+
}
821

922
// 2. Load PDF
1023
const pdfDoc = await PDFDocument.load(existingPdfBytes);

0 commit comments

Comments
 (0)