Skip to content

Commit 407c7dc

Browse files
committed
Logic fix for environment detection in contact API endpoint
1 parent d6cab0d commit 407c7dc

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

‎src/pages/api/contact/index.ts‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
* With Vercel adapter, this becomes a serverless function automatically
66
*/
77
import type { APIRoute } from 'astro'
8-
import { getSecret } from 'astro:env/server'
98
import { Resend } from 'resend'
109
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'
1213
import { checkContactRateLimit } from '@pages/api/_utils/rateLimit'
1314

1415
export const prerender = false // Force SSR for this endpoint
@@ -171,19 +172,11 @@ function formatFileSize(bytes: number): string {
171172
*/
172173
async function sendEmail(emailData: EmailData, files: FileAttachment[]): Promise<void> {
173174
// 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
176177
}
177178

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)
187180

188181
try {
189182
// Prepare attachments for Resend

0 commit comments

Comments
 (0)