diff --git a/package-lock.json b/package-lock.json index a2d51f0..cabc66f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,6 +34,7 @@ "tw-animate-css": "^1.4.0" }, "devDependencies": { + "@cloudflare/workers-types": "^4.20260403.1", "@types/react": "^19.2.14" } }, @@ -813,6 +814,14 @@ "node": ">=16" } }, + "node_modules/@cloudflare/workers-types": { + "version": "4.20260403.1", + "resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-4.20260403.1.tgz", + "integrity": "sha512-p6oSNt3yUwcxSoXZ7qCog7+kgQbkSx1Beoci7TMb/xbRF05VR0cO/p1XUE2SLHZ7IgSIc3tNMpFKa0L0fa3Lzg==", + "devOptional": true, + "license": "MIT OR Apache-2.0", + "peer": true + }, "node_modules/@cspotcode/source-map-support": { "version": "0.8.1", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", diff --git a/package.json b/package.json index 939cf05..352afb7 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "tw-animate-css": "^1.4.0" }, "devDependencies": { + "@cloudflare/workers-types": "^4.20260403.1", "@types/react": "^19.2.14" } } diff --git a/src/pages/api/contact.ts b/src/pages/api/contact.ts index 694c971..eb898ff 100644 --- a/src/pages/api/contact.ts +++ b/src/pages/api/contact.ts @@ -1,4 +1,5 @@ import type { APIRoute } from 'astro'; +import { env } from 'cloudflare:workers'; import { sendEmail } from '@/lib/email'; import general from '@/content/settings/general.json'; @@ -70,7 +71,7 @@ function buildContactNotificationHtml(data: ContactBody): string { `; } -export const POST: APIRoute = async ({ request, locals }) => { +export const POST: APIRoute = async ({ request }) => { let body: unknown; try { body = await request.json(); @@ -88,8 +89,7 @@ export const POST: APIRoute = async ({ request, locals }) => { }); } - const runtime = (locals as { runtime?: { env?: Record } }).runtime; - const apiKey = runtime?.env?.RESEND_API_KEY; + const apiKey = (env as unknown as Record).RESEND_API_KEY; const toAddress = general.emailToContact?.trim(); const fromAddress = general.emailFromContact?.trim(); if (!apiKey || !toAddress || !fromAddress) { diff --git a/src/pages/api/submission.ts b/src/pages/api/submission.ts index 0d932fa..345d7cf 100644 --- a/src/pages/api/submission.ts +++ b/src/pages/api/submission.ts @@ -1,4 +1,5 @@ import type { APIRoute } from 'astro'; +import { env } from 'cloudflare:workers'; import type { EmailAttachment } from '@/lib/email'; import { sendEmail } from '@/lib/email'; import general from '@/content/settings/general.json'; @@ -143,7 +144,7 @@ function buildNotificationHtml(data: SubmissionPayload, attachmentNames: string[ `; } -export const POST: APIRoute = async ({ request, locals }) => { +export const POST: APIRoute = async ({ request }) => { const contentType = request.headers.get('content-type') ?? ''; if (!contentType.includes('multipart/form-data')) { return new Response(JSON.stringify({ success: false, error: 'Invalid Content-Type.' }), { @@ -213,8 +214,7 @@ export const POST: APIRoute = async ({ request, locals }) => { }); } - const runtime = (locals as { runtime?: { env?: Record } }).runtime; - const apiKey = runtime?.env?.RESEND_API_KEY; + const apiKey = (env as unknown as Record).RESEND_API_KEY; const fromAddress = general.fromAddressSubmission?.trim(); const toAddress = general.toAddressSubmission?.trim(); diff --git a/tsconfig.json b/tsconfig.json index 948ca4c..0853aa6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,8 @@ "paths": { "@/*": ["src/*"] }, - "jsx": "react-jsx", - "jsxImportSource": "react" + "types": ["@cloudflare/workers-types"], + "jsx": "react-jsx", + "jsxImportSource": "react" } }