Fix Revisi Kak Inno 22 Oktober && Fix Revisi Kak Ayu 22 Oktober

This commit is contained in:
2025-10-23 17:45:45 +08:00
parent 0ff0d5234a
commit aa98359ef7
21 changed files with 320 additions and 139 deletions

View File

@@ -0,0 +1,54 @@
import { NextResponse } from 'next/server';
import nodemailer from 'nodemailer';
export async function POST(request: Request) {
try {
const { email } = await request.json();
// Input validation
if (!email) {
return NextResponse.json(
{ success: false, message: 'Email is required' },
{ status: 400 }
);
}
// Email regex validation
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
return NextResponse.json(
{ success: false, message: 'Invalid email format' },
{ status: 400 }
);
}
// Configure nodemailer
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS,
},
});
// Send email
await transporter.sendMail({
from: `"Tim Info" <${process.env.EMAIL_USER}>`,
to: email,
subject: '✅ Berhasil Berlangganan!',
html: `<p>Terima kasih telah berlangganan info terbaru dari kami!</p>`,
});
return NextResponse.json({
success: true,
message: 'Subscription successful! Please check your email.',
});
} catch (error) {
console.error('Error in subscribe API:', error);
return NextResponse.json(
{ success: false, message: 'Internal server error' },
{ status: 500 }
);
}
}