|
5 | 5 | * With Vercel adapter, this becomes a serverless function automatically |
6 | 6 | */ |
7 | 7 | import type { APIRoute } from 'astro' |
8 | | -import { getSecret } from 'astro:env/server' |
9 | 8 | import { Resend } from 'resend' |
10 | 9 | import { v4 as uuidv4, validate as uuidValidate } from 'uuid' |
11 | | -import { ClientScriptError } from '@components/scripts/errors/ClientScriptError' |
| 10 | +import { RESEND_API_KEY } from 'astro:env/server' |
| 11 | +import { ClientScriptError } from '@components/scripts/errors' |
| 12 | +import { isDev, isTest } from '@components/scripts/utils' |
12 | 13 | import { checkContactRateLimit } from '@pages/api/_utils/rateLimit' |
13 | 14 |
|
14 | 15 | export const prerender = false // Force SSR for this endpoint |
@@ -171,19 +172,11 @@ function formatFileSize(bytes: number): string { |
171 | 172 | */ |
172 | 173 | async function sendEmail(emailData: EmailData, files: FileAttachment[]): Promise<void> { |
173 | 174 | // Skip actual email sending in dev/test environments |
174 | | - if (getSecret('VITEST') || import.meta.env.DEV) { |
175 | | - return // Skip actual email sending in dev/test |
| 175 | + if (isTest() || isDev()) { |
| 176 | + return |
176 | 177 | } |
177 | 178 |
|
178 | | - const apiKey = import.meta.env['RESEND_API_KEY'] |
179 | | - |
180 | | - if (!apiKey) { |
181 | | - throw new ClientScriptError({ |
182 | | - message: 'Resend API key is not configured.' |
183 | | - }) |
184 | | - } |
185 | | - |
186 | | - const resend = new Resend(apiKey) |
| 179 | + const resend = new Resend(RESEND_API_KEY) |
187 | 180 |
|
188 | 181 | try { |
189 | 182 | // Prepare attachments for Resend |
|
0 commit comments