Repository navigation
Feature/webinar landing (#552) #553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,3 +18,4 @@ | |
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| .vercel | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| export default async function handler(req, res) { | ||
| const MAILERLITE_API_KEY = process.env.MAILERLITE_API_KEY | ||
| const MAILERLITE_GROUP_ID = process.env.MAILERLITE_GROUP_ID || process.env.NEXT_PUBLIC_MAILERLITE_WEBFORM_ID | ||
|
|
||
| // Enable CORS | ||
| res.setHeader('Access-Control-Allow-Credentials', 'true') | ||
| res.setHeader('Access-Control-Allow-Origin', '*') | ||
| res.setHeader('Access-Control-Allow-Methods', 'GET,OPTIONS,PATCH,DELETE,POST,PUT') | ||
| res.setHeader( | ||
| 'Access-Control-Allow-Headers', | ||
| 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version' | ||
| ) | ||
|
|
||
| if (req.method === 'OPTIONS') { | ||
| return res.status(200).end() | ||
| } | ||
|
|
||
| if (req.method !== 'POST') { | ||
| return res.status(405).json({ success: false, message: 'Method not allowed' }) | ||
| } | ||
|
|
||
| if (!MAILERLITE_API_KEY) { | ||
| console.error('MailerLite API key not configured') | ||
| return res.status(500).json({ | ||
| success: false, | ||
| message: 'Subscription service is not configured properly' | ||
| }) | ||
| } | ||
|
|
||
| try { | ||
| const body = req.body | ||
|
|
||
| if (!body.email) { | ||
| return res.status(400).json({ | ||
| success: false, | ||
| message: 'Email is required' | ||
| }) | ||
| } | ||
|
|
||
| // Build the MailerLite API payload | ||
| const payload = { | ||
| email: body.email, | ||
| status: 'active', | ||
| fields: body.fields || {} | ||
| } | ||
|
|
||
| if (body.name) { | ||
| payload.fields.name = body.name | ||
| } | ||
|
|
||
| if (body.resubscribe) { | ||
| payload.resubscribe = true | ||
| } | ||
|
|
||
| // Add to groups if specified | ||
| if (body.groups && body.groups.length > 0) { | ||
| payload.groups = body.groups | ||
| } else if (MAILERLITE_GROUP_ID) { | ||
| // Use default group if no specific groups provided | ||
| payload.groups = [MAILERLITE_GROUP_ID] | ||
| } | ||
|
|
||
| // Make request to MailerLite API | ||
| const response = await fetch('https://api.mailerlite.com/api/v2/subscribers', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| 'X-MailerLite-ApiKey': MAILERLITE_API_KEY | ||
| }, | ||
| body: JSON.stringify(payload) | ||
| }) | ||
|
|
||
| const data = await response.json() | ||
|
|
||
| if (!response.ok) { | ||
| // Check if subscriber already exists (200/201 are success, 400 might be duplicate) | ||
| if (response.status === 400 && data.message?.includes('already exists')) { | ||
| // Try to update existing subscriber | ||
| const updateResponse = await fetch(`https://api.mailerlite.com/api/v2/subscribers/${body.email}`, { | ||
| method: 'PUT', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| 'X-MailerLite-ApiKey': MAILERLITE_API_KEY | ||
| }, | ||
| body: JSON.stringify(payload) | ||
| }) | ||
|
|
||
| if (updateResponse.ok) { | ||
| const updateData = await updateResponse.json() | ||
| return res.status(200).json({ | ||
| success: true, | ||
| message: 'Successfully updated your subscription', | ||
| alreadySubscribed: true, | ||
| data: updateData | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| console.error('MailerLite API error:', data) | ||
| return res.status(response.status).json({ | ||
| success: false, | ||
| message: data.message || 'Failed to subscribe. Please try again.' | ||
| }) | ||
| } | ||
|
|
||
| return res.status(200).json({ | ||
| success: true, | ||
| message: 'Successfully subscribed!', | ||
| alreadySubscribed: false, | ||
| data: data | ||
| }) | ||
| } catch (error) { | ||
| console.error('Subscription error:', error) | ||
| return res.status(500).json({ | ||
| success: false, | ||
| message: 'An error occurred while processing your subscription' | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| { | ||
| // This file is not used in compilation. It is here just for a nice editor experience. | ||
| "extends": "@docusaurus/tsconfig", | ||
| "extends": "./node_modules/@docusaurus/tsconfig/tsconfig.json", | ||
| "compilerOptions": { | ||
| "baseUrl": "." | ||
| } | ||
| }, | ||
| "include": ["src", "docs"], | ||
| "exclude": ["node_modules", "build", "api"] | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] URL-encode email before calling MailerLite update endpoint
When handling a duplicate subscriber, the code constructs the update URL with
https://api.mailerlite.com/api/v2/subscribers/${body.email}. If the email contains characters that are not legal in a path segment (e.g.+, spaces, non‑ASCII), the request will be interpreted incorrectly by the MailerLite API and the update attempt will fail. This means users who sign up with common aliasing patterns likeuser+promo@example.comwill never get the graceful "already subscribed" path and will continue receiving an error. Wrap the email withencodeURIComponentbefore interpolating it into the URL.Useful? React with 👍 / 👎.