Add comprehensive server-side logging to QR code generation API
Some checks failed
Build and Push Docker Images / docker (push) Has been cancelled
Some checks failed
Build and Push Docker Images / docker (push) Has been cancelled
This commit is contained in:
parent
4adb7b0101
commit
1bf06a2a68
@ -9,13 +9,19 @@ import { validateQRData, sanitizeQRData } from '@/src/utils/qrDataValidator';
|
|||||||
import { generateCalculatorQRCode } from '@/src/utils/qrCodeGenerator';
|
import { generateCalculatorQRCode } from '@/src/utils/qrCodeGenerator';
|
||||||
|
|
||||||
export async function POST(request: NextRequest) {
|
export async function POST(request: NextRequest) {
|
||||||
|
console.log('[QR API] POST /api/qr-code/generate - Request received');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Parse request body
|
// Parse request body
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
|
console.log('[QR API] Request body parsed:', JSON.stringify(body, null, 2));
|
||||||
|
|
||||||
// Validate data
|
// Validate data
|
||||||
|
console.log('[QR API] Validating QR data...');
|
||||||
const validationResult = validateQRData(body);
|
const validationResult = validateQRData(body);
|
||||||
|
|
||||||
if (!validationResult.valid) {
|
if (!validationResult.valid) {
|
||||||
|
console.error('[QR API] Validation failed:', validationResult.error);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: false,
|
success: false,
|
||||||
@ -24,19 +30,24 @@ export async function POST(request: NextRequest) {
|
|||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
console.log('[QR API] Validation successful');
|
||||||
|
|
||||||
const data = validationResult.data as QRCalculatorData;
|
const data = validationResult.data as QRCalculatorData;
|
||||||
|
|
||||||
// Sanitize data to remove any unnecessary fields
|
// Sanitize data to remove any unnecessary fields
|
||||||
const cleanedData = sanitizeQRData(data);
|
const cleanedData = sanitizeQRData(data);
|
||||||
|
console.log('[QR API] Data sanitized');
|
||||||
|
|
||||||
// Get base URL from request
|
// Get base URL from request
|
||||||
const protocol = request.headers.get('x-forwarded-proto') || 'https';
|
const protocol = request.headers.get('x-forwarded-proto') || 'https';
|
||||||
const host = request.headers.get('host') || 'localhost:3000';
|
const host = request.headers.get('host') || 'localhost:3000';
|
||||||
const baseUrl = `${protocol}://${host}`;
|
const baseUrl = `${protocol}://${host}`;
|
||||||
|
console.log('[QR API] Base URL:', baseUrl);
|
||||||
|
|
||||||
// Generate QR code
|
// Generate QR code
|
||||||
|
console.log('[QR API] Generating QR code...');
|
||||||
const { dataURL, svg, url } = await generateCalculatorQRCode(cleanedData, baseUrl);
|
const { dataURL, svg, url } = await generateCalculatorQRCode(cleanedData, baseUrl);
|
||||||
|
console.log('[QR API] QR code generated successfully, URL:', url);
|
||||||
|
|
||||||
// Set expiration time (30 days from now)
|
// Set expiration time (30 days from now)
|
||||||
const expiresAt = new Date();
|
const expiresAt = new Date();
|
||||||
@ -50,12 +61,14 @@ export async function POST(request: NextRequest) {
|
|||||||
expiresAt: expiresAt.toISOString(),
|
expiresAt: expiresAt.toISOString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log('[QR API] Sending success response');
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
data: response,
|
data: response,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error generating QR code:', error);
|
console.error('[QR API] Error generating QR code:', error);
|
||||||
|
console.error('[QR API] Error stack:', error instanceof Error ? error.stack : 'No stack trace');
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
@ -69,6 +82,7 @@ export async function POST(request: NextRequest) {
|
|||||||
|
|
||||||
// Return method not allowed for other HTTP methods
|
// Return method not allowed for other HTTP methods
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
|
console.log('[QR API] GET /api/qr-code/generate - Method not allowed');
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: false,
|
success: false,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user