Skip to content

Commit e334c1f

Browse files
committed
fix env, mailto fallback
1 parent fe959d5 commit e334c1f

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/routes/contact/+page.server.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { redirect } from '@sveltejs/kit';
22
import type { Actions } from '../company/$types';
33

4-
import { MM_WEBHOOK } from '$env/static/private';
4+
import { env } from '$env/dynamic/private';
55

66
export const actions = {
77
default: async ({ request }) => {
8+
const webhook = env.MM_WEBHOOK;
9+
810
const data = await request.formData();
911

1012
const name = data.get('name') || '-';
@@ -14,11 +16,11 @@ export const actions = {
1416
const message = data.get('message') || '-';
1517

1618
try {
17-
if (!MM_WEBHOOK) {
19+
if (!webhook) {
1820
throw new Error('Missing webhook URL');
1921
}
2022

21-
const res = await fetch(MM_WEBHOOK, {
23+
const res = await fetch(webhook, {
2224
method: 'post',
2325
headers: {
2426
'content-type': 'application/json'
@@ -47,21 +49,20 @@ ${message}
4749

4850
// webhook failed, let's redirect to a mailto link instead
4951

50-
const params = new URLSearchParams();
51-
params.append('subject', 'Farad Contact Form Submission');
52-
params.append(
53-
'body',
54-
`${message}
52+
let query = '';
53+
query += 'subject=' + encodeURIComponent('Farad Contact Form Submission');
54+
query +=
55+
'&body=' +
56+
encodeURIComponent(`${message}
5557
5658
---
5759
5860
Name: ${name}
5961
Email: ${email}
6062
Company: ${company}
61-
Phone: ${phone}`
62-
);
63+
Phone: ${phone}`);
6364

64-
redirect(303, 'mailto:farad@fsektionen.se?' + params.toString());
65+
redirect(303, 'mailto:farad@fsektionen.se?' + query);
6566
}
6667
}
6768
} satisfies Actions;

0 commit comments

Comments
 (0)