test/user-journey #3

Merged
zhangxiang merged 142 commits from test/user-journey into dev 2026-04-12 13:17:03 +08:00
2 changed files with 28 additions and 4 deletions
Showing only changes of commit 8b7cc15362 - Show all commits
+14 -2
View File
@@ -3,9 +3,21 @@
import { Resend } from 'resend';
import { z } from 'zod';
const resend = new Resend(process.env.RESEND_API_KEY);
const companyEmail = process.env.COMPANY_EMAIL || 'contact@novalon.cn';
let resend: Resend | null = null;
function getResend(): Resend {
if (!resend) {
const apiKey = process.env.RESEND_API_KEY;
if (!apiKey) {
throw new Error('RESEND_API_KEY environment variable is not set');
}
resend = new Resend(apiKey);
}
return resend;
}
const contactFormSchema = z.object({
name: z.string().min(2, '姓名至少需要2个字符'),
phone: z.string().regex(/^1[3-9]\d{9}$/, '请输入有效的手机号码'),
@@ -244,7 +256,7 @@ export async function submitContactForm(
`;
try {
const { data: emailData, error } = await resend.emails.send({
const { data: emailData, error } = await getResend().emails.send({
from: '睿新致远官网 <onboarding@resend.dev>',
to: [companyEmail],
subject: `📧 ${data.subject} - ${data.name}`,
+14 -2
View File
@@ -3,9 +3,21 @@ import { Resend } from 'resend';
import { z } from 'zod';
import { SecurityMiddleware } from '@/lib/security/middleware';
const resend = new Resend(process.env.RESEND_API_KEY);
const companyEmail = process.env.COMPANY_EMAIL || 'contact@novalon.cn';
let resend: Resend | null = null;
function getResend(): Resend {
if (!resend) {
const apiKey = process.env.RESEND_API_KEY;
if (!apiKey) {
throw new Error('RESEND_API_KEY environment variable is not set');
}
resend = new Resend(apiKey);
}
return resend;
}
let securityMiddleware = new SecurityMiddleware();
export function setSecurityMiddleware(middleware: SecurityMiddleware) {
@@ -108,7 +120,7 @@ export async function POST(request: NextRequest) {
</html>
`;
const result = await resend.emails.send({
const result = await getResend().emails.send({
from: '睿新致远官网 <onboarding@resend.dev>',
to: [companyEmail],
subject: `${sanitizedData.subject} - ${sanitizedData.name}`,