Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions www/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
STACKS_API_KEY=[ask_hugh]
1 change: 1 addition & 0 deletions www/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ yarn-error.log*

# env files (can opt-in for committing if needed)
.env*
!.env.example

# vercel
.vercel
Expand Down
1 change: 1 addition & 0 deletions www/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 20.19.6
68 changes: 27 additions & 41 deletions www/app/api/subscribe/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,39 @@ export async function POST(request: NextRequest): Promise<NextResponse<Subscribe

const normalizedEmail = email.toLowerCase().trim();

// Check if already subscribed
if (subscribedEmails.has(normalizedEmail)) {
const response = await fetch('https://stacks.garden3d.net/api/contacts', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Api-Key': process.env.STACKS_API_KEY!,
},
body: JSON.stringify({
email: normalizedEmail,
sources: ['g3d:family_intelligence']
}),
});

if (response.ok) {
return NextResponse.json(
{
success: true,
message: 'This email is already subscribed to our updates.',
status: 'already_subscribed',
message: 'Thank you for subscribing! We\'ll keep you updated.',
status: 'subscribed',
},
{ status: 201 }
);
} else {
console.error('Subscription error:', response.statusText);
return NextResponse.json(
{
success: false,
message: 'Something went wrong. Please try again later.',
status: 'error',
},
{ status: 200 }
{ status: 500 }
);
}

// Add to subscribers (in production, save to database/email service)
subscribedEmails.add(normalizedEmail);

// Success response
return NextResponse.json(
{
success: true,
message: 'Thank you for subscribing! We\'ll keep you updated.',
status: 'subscribed',
},
{ status: 201 }
);

} catch (error) {
console.error('Subscription error:', error);

Expand All @@ -81,26 +89,4 @@ export async function POST(request: NextRequest): Promise<NextResponse<Subscribe
{ status: 500 }
);
}
}

// GET endpoint to check subscription status (optional utility)
export async function GET(request: NextRequest): Promise<NextResponse> {
const { searchParams } = new URL(request.url);
const email = searchParams.get('email');

if (!email) {
return NextResponse.json(
{ error: 'Email parameter required' },
{ status: 400 }
);
}

const normalizedEmail = email.toLowerCase().trim();
const isSubscribed = subscribedEmails.has(normalizedEmail);

return NextResponse.json({
email: normalizedEmail,
subscribed: isSubscribed,
});
}

}
Loading