fix apis
This commit is contained in:
9
package-lock.json
generated
9
package-lock.json
generated
@@ -34,6 +34,7 @@
|
|||||||
"tw-animate-css": "^1.4.0"
|
"tw-animate-css": "^1.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@cloudflare/workers-types": "^4.20260403.1",
|
||||||
"@types/react": "^19.2.14"
|
"@types/react": "^19.2.14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -813,6 +814,14 @@
|
|||||||
"node": ">=16"
|
"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": {
|
"node_modules/@cspotcode/source-map-support": {
|
||||||
"version": "0.8.1",
|
"version": "0.8.1",
|
||||||
"resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz",
|
"resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz",
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
"tw-animate-css": "^1.4.0"
|
"tw-animate-css": "^1.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@cloudflare/workers-types": "^4.20260403.1",
|
||||||
"@types/react": "^19.2.14"
|
"@types/react": "^19.2.14"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { APIRoute } from 'astro';
|
import type { APIRoute } from 'astro';
|
||||||
|
import { env } from 'cloudflare:workers';
|
||||||
import { sendEmail } from '@/lib/email';
|
import { sendEmail } from '@/lib/email';
|
||||||
import general from '@/content/settings/general.json';
|
import general from '@/content/settings/general.json';
|
||||||
|
|
||||||
@@ -70,7 +71,7 @@ function buildContactNotificationHtml(data: ContactBody): string {
|
|||||||
</html>`;
|
</html>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const POST: APIRoute = async ({ request, locals }) => {
|
export const POST: APIRoute = async ({ request }) => {
|
||||||
let body: unknown;
|
let body: unknown;
|
||||||
try {
|
try {
|
||||||
body = await request.json();
|
body = await request.json();
|
||||||
@@ -88,8 +89,7 @@ export const POST: APIRoute = async ({ request, locals }) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const runtime = (locals as { runtime?: { env?: Record<string, string> } }).runtime;
|
const apiKey = (env as unknown as Record<string, string>).RESEND_API_KEY;
|
||||||
const apiKey = runtime?.env?.RESEND_API_KEY;
|
|
||||||
const toAddress = general.emailToContact?.trim();
|
const toAddress = general.emailToContact?.trim();
|
||||||
const fromAddress = general.emailFromContact?.trim();
|
const fromAddress = general.emailFromContact?.trim();
|
||||||
if (!apiKey || !toAddress || !fromAddress) {
|
if (!apiKey || !toAddress || !fromAddress) {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { APIRoute } from 'astro';
|
import type { APIRoute } from 'astro';
|
||||||
|
import { env } from 'cloudflare:workers';
|
||||||
import type { EmailAttachment } from '@/lib/email';
|
import type { EmailAttachment } from '@/lib/email';
|
||||||
import { sendEmail } from '@/lib/email';
|
import { sendEmail } from '@/lib/email';
|
||||||
import general from '@/content/settings/general.json';
|
import general from '@/content/settings/general.json';
|
||||||
@@ -143,7 +144,7 @@ function buildNotificationHtml(data: SubmissionPayload, attachmentNames: string[
|
|||||||
</html>`;
|
</html>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const POST: APIRoute = async ({ request, locals }) => {
|
export const POST: APIRoute = async ({ request }) => {
|
||||||
const contentType = request.headers.get('content-type') ?? '';
|
const contentType = request.headers.get('content-type') ?? '';
|
||||||
if (!contentType.includes('multipart/form-data')) {
|
if (!contentType.includes('multipart/form-data')) {
|
||||||
return new Response(JSON.stringify({ success: false, error: 'Invalid Content-Type.' }), {
|
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<string, string> } }).runtime;
|
const apiKey = (env as unknown as Record<string, string>).RESEND_API_KEY;
|
||||||
const apiKey = runtime?.env?.RESEND_API_KEY;
|
|
||||||
const fromAddress = general.fromAddressSubmission?.trim();
|
const fromAddress = general.fromAddressSubmission?.trim();
|
||||||
const toAddress = general.toAddressSubmission?.trim();
|
const toAddress = general.toAddressSubmission?.trim();
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["src/*"]
|
"@/*": ["src/*"]
|
||||||
},
|
},
|
||||||
|
"types": ["@cloudflare/workers-types"],
|
||||||
"jsx": "react-jsx",
|
"jsx": "react-jsx",
|
||||||
"jsxImportSource": "react"
|
"jsxImportSource": "react"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user