refactor: completely remove payload cms and convert to static/mdx approaches
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getPayload } from "payload";
|
||||
import configPromise from "@payload-config";
|
||||
import { getServerAppServices } from "@/lib/services/create-services.server";
|
||||
import {
|
||||
render,
|
||||
@@ -50,34 +48,6 @@ export async function POST(req: Request) {
|
||||
return NextResponse.json({ error: "message_too_long" }, { status: 400 });
|
||||
}
|
||||
|
||||
const payload = await getPayload({ config: configPromise });
|
||||
|
||||
// 1. Payload save
|
||||
let payloadSaved = false;
|
||||
try {
|
||||
await payload.create({
|
||||
collection: "form-submissions",
|
||||
data: {
|
||||
name,
|
||||
email,
|
||||
company: company || "Nicht angegeben",
|
||||
message,
|
||||
},
|
||||
});
|
||||
logger.info("Contact submission saved to PayloadCMS");
|
||||
payloadSaved = true;
|
||||
} catch (payloadError) {
|
||||
const errorMessage =
|
||||
payloadError instanceof Error
|
||||
? payloadError.message
|
||||
: String(payloadError);
|
||||
logger.error("Failed to save to Payload", {
|
||||
error: errorMessage,
|
||||
details: payloadError,
|
||||
});
|
||||
services.errors.captureException(payloadError, { phase: "payload_save" });
|
||||
}
|
||||
|
||||
// 2. Email sending via standalone Nodemailer (bypassing Payload adapter)
|
||||
try {
|
||||
const { config } = await import("@/lib/config");
|
||||
@@ -87,7 +57,7 @@ export async function POST(req: Request) {
|
||||
const recipients = Array.isArray(config.mail.recipients)
|
||||
? config.mail.recipients.filter(Boolean)
|
||||
: [];
|
||||
|
||||
|
||||
const to =
|
||||
recipients.length > 0
|
||||
? recipients.join(",")
|
||||
@@ -103,7 +73,10 @@ export async function POST(req: Request) {
|
||||
},
|
||||
});
|
||||
|
||||
logger.info("Preparing to send notification email", { to, host: config.mail.host });
|
||||
logger.info("Preparing to send notification email", {
|
||||
to,
|
||||
host: config.mail.host,
|
||||
});
|
||||
|
||||
// 2a. Notification to MB Grid
|
||||
const notificationHtml = await render(
|
||||
@@ -123,9 +96,13 @@ export async function POST(req: Request) {
|
||||
subject: `Kontaktanfrage von ${name}`,
|
||||
html: notificationHtml,
|
||||
});
|
||||
logger.info("Notification email sent successfully", { messageId: info?.messageId });
|
||||
logger.info("Notification email sent successfully", {
|
||||
messageId: info?.messageId,
|
||||
});
|
||||
} catch (notifyError) {
|
||||
logger.error("Failed to send notification email", { error: notifyError });
|
||||
logger.error("Failed to send notification email", {
|
||||
error: notifyError,
|
||||
});
|
||||
throw notifyError; // Re-throw to be caught by the outer SMTP catch
|
||||
}
|
||||
|
||||
@@ -145,11 +122,18 @@ export async function POST(req: Request) {
|
||||
subject: `Ihre Kontaktanfrage bei ${clientName}`,
|
||||
html: confirmationHtml,
|
||||
});
|
||||
logger.info("Confirmation email sent successfully", { messageId: info?.messageId });
|
||||
logger.info("Confirmation email sent successfully", {
|
||||
messageId: info?.messageId,
|
||||
});
|
||||
} catch (confirmError) {
|
||||
logger.warn(
|
||||
"Failed to send confirmation email, but notification was sent",
|
||||
{ error: confirmError instanceof Error ? confirmError.message : String(confirmError) },
|
||||
{
|
||||
error:
|
||||
confirmError instanceof Error
|
||||
? confirmError.message
|
||||
: String(confirmError),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -165,18 +149,10 @@ export async function POST(req: Request) {
|
||||
logger.error("SMTP Error", { error: smtpError });
|
||||
services.errors.captureException(smtpError, { phase: "smtp_send" });
|
||||
|
||||
if (!payloadSaved) {
|
||||
return NextResponse.json(
|
||||
{ error: "Systemfehler (Speicherung und Versand fehlgeschlagen)" },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
|
||||
await services.notifications.notify({
|
||||
title: "🚨 SMTP Fehler (Kontaktformular)",
|
||||
message: `Anfrage von ${name} (${email}) in Payload gespeichert, aber E-Mail-Versand fehlgeschlagen: ${smtpError instanceof Error ? smtpError.message : String(smtpError)}`,
|
||||
priority: 8,
|
||||
});
|
||||
return NextResponse.json(
|
||||
{ error: "Systemfehler (E-Mail-Versand fehlgeschlagen)" },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
|
||||
// Track success
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getPayload } from "payload";
|
||||
import configPromise from "@payload-config";
|
||||
import { getServerAppServices } from "@/lib/services/create-services.server";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const authHeader = req.headers.get("authorization");
|
||||
if (authHeader !== `Bearer ${process.env.PAYLOAD_SECRET}`) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { logger } = getServerAppServices();
|
||||
|
||||
try {
|
||||
logger.info("Starting programmatic Payload migrations...");
|
||||
const payload = await getPayload({ config: configPromise });
|
||||
|
||||
await payload.db.migrate();
|
||||
|
||||
logger.info("Successfully executed Payload migrations.");
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Migrations executed successfully.",
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error("Failed to run migrations remotely", { error });
|
||||
return NextResponse.json(
|
||||
{
|
||||
error:
|
||||
error instanceof Error ? error.message : "Unknown error occurred",
|
||||
},
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user