Skip to content

Commit be1158d

Browse files
committed
updated register and subscribe requests.
1 parent 58054e2 commit be1158d

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

app/register/page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export default function RegisterPage() {
2424
setError('');
2525

2626
try {
27-
const response = await fetch('/api/register', {
27+
// Use external API endpoint for GitHub Pages deployment
28+
const apiUrl = process.env.NEXT_PUBLIC_REGISTER_API_URL || '/api/register';
29+
const response = await fetch(apiUrl, {
2830
method: 'POST',
2931
headers: {
3032
'Content-Type': 'application/json',

components/NewsletterSignup.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,29 @@ export default function NewsletterSignup() {
1010
const handleSubmit = async (e: React.FormEvent) => {
1111
e.preventDefault();
1212
setStatus('loading');
13+
1314
try {
14-
const formData = new URLSearchParams();
15-
formData.append("email-address", email);
16-
17-
await fetch(process.env.MAILMAN_SUBSCRIBE_URL!, {
18-
method: "POST",
19-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
20-
body: formData.toString(),
15+
// Use external API endpoint for GitHub Pages deployment
16+
const apiUrl = process.env.NEXT_PUBLIC_NEWSLETTER_API_URL || '/api/newsletter';
17+
const response = await fetch(apiUrl, {
18+
method: 'POST',
19+
headers: { 'Content-Type': 'application/json' },
20+
body: JSON.stringify({ email }),
2121
});
2222

23+
const data = await response.json();
24+
25+
if (!response.ok) {
26+
throw new Error(data.error || 'Subscription failed');
27+
}
28+
2329
console.log('Email submitted:', email);
24-
// Alert message will be shown by the success status div below
2530
setSubmittedEmail(email);
2631
setStatus('success');
2732
setEmail('');
28-
2933
} catch (error) {
3034
console.error('Error submitting email:', error);
3135
setStatus('error');
32-
return;
3336
}
3437
};
3538

0 commit comments

Comments
 (0)