The backend API is a Node.js Express server that handles Stripe webhooks, payment processing, and email notifications.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/aluxey/E-Commerce/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The API server (api/src/server.js) provides:
- Stripe webhook handling for payment confirmations
- Payment intent creation for checkout
- Email notifications via Resend or Nodemailer
- Image upload with Multer
- Supabase integration with service role key
Prerequisites
- Node.js 18+ hosting platform (Railway, Render, Fly.io, or VPS)
- Environment variables from Stripe and Supabase
- Domain or public URL for webhooks
Deployment Options
Railway
Easy deployment with automatic HTTPS
Render
Free tier available for testing
Fly.io
Global edge deployment
Environment Variables
Deployment Steps
- Railway
- Render
- Docker
Package Configuration
Theapi/package.json defines startup scripts:
package.json
| Script | Usage |
|---|---|
npm run dev | Development with hot-reload and .env file |
npm start | Production mode (reads env vars from platform) |
Configure Stripe Webhook
Create Webhook in Stripe
- Go to Stripe Dashboard → Webhooks
- Click Add endpoint
- Set endpoint URL:
https://your-api.railway.app/webhook - Select events:
payment_intent.succeededpayment_intent.payment_failedcharge.refunded
Copy Webhook Secret
After creating the webhook, Stripe provides a signing secret:Add this to your environment variables as
STRIPE_WEBHOOK_SECRET.Health Check
Verify the API is running:Monitoring and Logs
Troubleshooting
Webhook signature verification fails
Webhook signature verification fails
Error:
Webhook signature verification failedSolutions:- Verify
STRIPE_WEBHOOK_SECRETmatches the secret from Stripe dashboard - Ensure webhook endpoint URL is correct
- Check that raw body is preserved (Express raw body parser)
CORS errors from frontend
CORS errors from frontend
Error:
Access-Control-Allow-Origin header missingSolution: Add frontend URL to CLIENT_ORIGIN:Email sending fails
Email sending fails
Resend: Verify
RESEND_API_KEY and that sending domain is verifiedNodemailer: For Gmail, use an App Password, not your regular passwordSupabase connection errors
Supabase connection errors
Error:
Invalid API keySolution: Ensure you’re using the service role key, not the anon key. The service role key has full database access.Production Checklist
- All environment variables set with production values
-
STRIPE_SECRET_KEYis live mode (starts withsk_live_) -
STRIPE_WEBHOOK_SECRETconfigured and tested -
CLIENT_ORIGINincludes production frontend URL - Webhook endpoint registered in Stripe dashboard
- Email service configured (Resend or Nodemailer)
- Health check endpoint returns 200
- Logs show no startup errors
- Test payment flow end-to-end
Next Steps
Frontend Deployment
Connect the frontend to your deployed API
Database Migrations
Set up and run production database migrations