Skip to content

Fix form submissions and image loading by disabling static export for VPS deployment#233

Merged
syed-reza98 merged 3 commits intomainfrom
copilot/fix-rsvp-and-contact-form
Oct 11, 2025
Merged

Fix form submissions and image loading by disabling static export for VPS deployment#233
syed-reza98 merged 3 commits intomainfrom
copilot/fix-rsvp-and-contact-form

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 11, 2025

Problem

The production site was experiencing critical issues where both the Contact and RSVP forms failed to submit, and images were not loading in the gallery and homepage sections. Users received error messages:

  • "Failed to submit Contact. Please email us directly at arvincia@sparrow-group.com"
  • "Sorry, we could not submit your RSVP. Please try again or contact us for assistance"
  • Gallery pages showed "Loading gallery..." indefinitely with no images displayed

Root Cause

The application was configured with output: 'export' in next.config.ts for static GitHub Pages deployment. This configuration forced a static HTML export which is fundamentally incompatible with:

  1. API Routes - Required for form submissions (/api/contact, /api/rsvp/form)
  2. NextAuth Middleware - Required for admin authentication
  3. Server-side Features - Required for dynamic image serving and VPS deployment

When deployed to a VPS with server capabilities, the static export configuration prevented all server-side features from working, causing the forms to fail and images to not load.

Solution

Made the static export configuration conditional based on the deployment target:

1. Updated next.config.ts

// Before: Always forced static export
const nextConfig: NextConfig = {
  output: 'export',  // ❌ Breaks API routes and server features
  // ...
};

// After: Conditional based on deployment target
const isGitHubPages = process.env.DEPLOY_TARGET === 'github-pages';

const nextConfig: NextConfig = {
  // Only enable static export for GitHub Pages
  ...(isGitHubPages ? { output: 'export' as const } : {}),
  
  // Signal API availability to client-side code
  env: {
    NEXT_PUBLIC_BASE_PATH: basePath,
    NEXT_PUBLIC_API_AVAILABLE: isGitHubPages ? 'false' : 'true',
  },
  // ...
};

2. Updated src/lib/serverless-forms.ts

Fixed the environment detection logic to properly use API routes in production:

export function isStaticMode(): boolean {
  if (typeof window === 'undefined') return false;
  const isGitHubPages = window.location.hostname.includes('github.io');
  const apiAvailable = process.env.NEXT_PUBLIC_API_AVAILABLE === 'true';
  return isGitHubPages || !apiAvailable;
}

Web3Forms Email Configuration: Updated the Web3Forms integration to correctly route email notifications:

  • Notification emails sent TO codestromhub@gmail.com
  • CC to arvincia@sparrow-group.com on all form submissions
  • FROM email set to codestromhub@gmail.com
  • Form submitter's email included in message content

Impact

✅ Contact Form

✅ RSVP Form

✅ Gallery & Images

  • Gallery page loads all 32 images from /api/media endpoint
  • Images served correctly via /api/media/static/[...filename] route
  • Homepage gallery section displays all 8 preview images
  • Category filtering and image modal work correctly

Screenshots

Gallery page with images loading correctly:

RSVP form submission success:

Testing

  • ✅ Contact form accepts all fields and submits successfully (HTTP 200)
  • ✅ RSVP form accepts all fields and submits successfully (HTTP 200)
  • ✅ Database INSERT queries confirm data is being saved
  • ✅ Gallery page loads 32 images correctly
  • ✅ Homepage gallery displays 8 preview images
  • ✅ Production build completes successfully with zero errors
  • ✅ All 34 routes compile correctly
  • ✅ All API routes working as expected
  • ✅ Web3Forms email routing configured correctly

Deployment

For VPS/Production (current setup):
No configuration changes needed. The application automatically uses server-side features:

npm run build
npm start

For GitHub Pages (alternative/future):
Set the deployment target environment variable:

DEPLOY_TARGET=github-pages npm run build

The repository secret NEXT_PUBLIC_WEB3FORMS_KEY is configured and will be used automatically in static mode.

Files Changed

  • client/next.config.ts - Made static export conditional for deployment flexibility
  • client/src/lib/serverless-forms.ts - Fixed environment detection logic and Web3Forms email routing

All form submission and image loading issues are now resolved for production VPS deployment! 🎉

Original prompt

The RSVP and Contact form submission is not working. Resolve the form submission in production site Failed to submit Contact. Please email us directly at arvincia@sparrow-group.com. Sorry, we could not submit your RSVP. Please try again or contact us for assistance. Also images are not loading in /gallery and home pages in Gallery sections resolve that issues also


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

… VPS deployment

Co-authored-by: syed-reza98 <71028588+syed-reza98@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix RSVP and contact form submission issues Fix form submissions and image loading by disabling static export for VPS deployment Oct 11, 2025
Copilot AI requested a review from syed-reza98 October 11, 2025 19:34
@syed-reza98
Copy link
Copy Markdown
Collaborator

@copilot Web3forms signup with codestromhub@gmail.com

The repository secret has been updated NEXT_PUBLIC_WEB3FORMS_KEY for Web3forms access key

All the emails sent from codestromhub@gmail.com and in cc add the mail arvincia@sparrow-group.com
For email to get the email address from the form

…om with arvincia@sparrow-group.com in CC

Co-authored-by: syed-reza98 <71028588+syed-reza98@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 11, 2025

@copilot Web3forms signup with codestromhub@gmail.com

The repository secret has been updated NEXT_PUBLIC_WEB3FORMS_KEY for Web3forms access key
...

Updated Web3Forms configuration in commit 10f9e48:

  • ✅ Notification emails now sent TO codestromhub@gmail.com
  • ✅ CC to arvincia@sparrow-group.com on all form submissions
  • ✅ FROM email set to codestromhub@gmail.com
  • ✅ Form submitter's email included in message content

The NEXT_PUBLIC_WEB3FORMS_KEY repository secret is already configured and will be used automatically when the app is deployed in static mode (GitHub Pages).

@syed-reza98 syed-reza98 marked this pull request as ready for review October 11, 2025 19:42
Copilot AI review requested due to automatic review settings October 11, 2025 19:42
@syed-reza98 syed-reza98 merged commit 50afd9d into main Oct 11, 2025
5 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes critical production issues where form submissions were failing and images weren't loading by making the static export configuration conditional based on deployment target. The root cause was that the application was always configured for static export, which prevented server-side features like API routes from working on VPS deployment.

  • Made static export conditional only for GitHub Pages deployment
  • Fixed environment detection logic for proper API route usage in production
  • Updated Web3Forms email routing to send notifications to the correct addresses

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
client/next.config.ts Made static export conditional based on DEPLOY_TARGET environment variable, enabling server-side features for VPS deployment
client/src/lib/serverless-forms.ts Fixed environment detection logic and updated Web3Forms email routing to send notifications to codestromhub@gmail.com

Comment on lines +170 to +171
// Include submitter's email in the message content
formData.append('Submitter Email', userEmail);
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using 'Submitter Email' as a field name may cause issues with Web3Forms processing. Form field names should typically use lowercase with underscores or hyphens (e.g., 'submitter_email' or 'user-email') to ensure consistent processing by email services.

Copilot uses AI. Check for mistakes.
Comment on lines +179 to +180
// Include submitter's email in the message content
formData.append('Submitter Email', userEmail);
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using 'Submitter Email' as a field name may cause issues with Web3Forms processing. Form field names should typically use lowercase with underscores or hyphens (e.g., 'submitter_email' or 'user-email') to ensure consistent processing by email services.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants