Feature Request System - Integration Fixes & Deployment Guide
Date: 2026-01-12
Status: ✅ Issues Fixed - Ready for Testing
Problems Identified & Fixed
1. ✅ Cloud Functions 500 Error
Problem: createFeatureRequest Cloud Function was returning 500 Internal Server Error.
Root Cause:
- Environment variables not properly configured for local development
- Using
defineStringparameters without proper fallback handling - Hardcoded GitHub token exposed in code (security risk)
- Octokit method call using
.issues.create()instead of.rest.issues.create()
Fixes Applied:
- ✅ Rewrote environment configuration handler to properly load from
.runtimeconfig.jsonfirst, thenprocess.env - ✅ Removed hardcoded token and implemented proper fallback chain
- ✅ Created
.runtimeconfig.jsonwith proper structure for local development - ✅ Fixed Octokit API call to use
.rest.issues.create()(correct v20 syntax) - ✅ Improved error logging to show which env vars are set/missing
Files Modified:
functions/index.js- Updated environment handling and Octokit callsfunctions/.runtimeconfig.json- NEW - Local development config
2. ✅ Service Worker MIME Type Error
Problem: Service worker was being served as HTML with error "The script has an unsupported MIME type ('text/html')"
Root Cause:
- Cloudflare Pages SPA rewrite rule (
/* /index.html 200) was catching the/sw.jsrequest - Service worker request was being served index.html instead of the actual
.jsfile - This is a deployment configuration issue, not a code issue
Fixes Applied:
- ✅ Updated
public/_redirectsto explicitly exclude/sw.jsfrom SPA fallback - ✅ Added explicit redirect rule:
/sw.js /sw.js 200!with!flag to prevent further rewriting - ✅ Added server configuration to
vite.config.mjsfor development environment
Files Modified:
public/_redirects- Added service worker bypass rulevite.config.mjs- Added server configuration for dev environment
Testing Instructions
1. Local Development Testing
Prerequisites:
- Node.js 20+
- Firebase CLI installed
- Access to Firebase project credentials
Steps:
# 1. Install dependencies
npm install
cd functions && npm install && cd ..
# 2. Verify environment configuration
cat functions/.runtimeconfig.json # Should show GitHub token and Discord webhook
# 3. Start Firebase emulators (optional but recommended)
firebase emulators:start
# 4. In another terminal, start dev server
npm run dev
# 5. Test form submission
# Navigate to http://localhost:5173/#/feedback
# Fill out form and submit
# Check browser console for any errorsExpected Results:
- ✅ Form submission completes without error
- ✅ Browser console shows success message with GitHub issue link
- ✅ GitHub issue created with correct labels and description
- ✅ Discord notification appears in configured channel (if webhook set)
- ✅ Firestore document created in
featureRequestscollection
2. Service Worker Testing
In Browser DevTools:
// Chrome DevTools > Application tab > Service Workers
// Should show: Service Worker (registration scope /)
// Status: running (or activated and running)
// If still showing MIME type error:
// 1. Check Application > Cache Storage
// 2. Clear all caches
// 3. Hard refresh (Ctrl+Shift+R or Cmd+Shift+R)
// 4. Check Network tab for /sw.js request (should be 200 OK with application/javascript MIME type)3. Cloud Functions Testing
Local Testing:
# Test checkDuplicates function
firebase functions:shell
# In the shell:
checkDuplicates({ title: 'test', description: 'test request' })
# Test createFeatureRequest (requires auth)
# Use postman or client-side code to call the functionProduction Testing:
# Check deployed function logs
firebase functions:log --project lantern-app-dev
# Look for these log lines indicating success:
# ✅ Creating GitHub issue with: {...}
# ✅ GitHub issue created: {...}
# ✅ Discord notification sent (if webhook configured)Deployment Instructions
Step 1: Deploy to Firebase Dev
# Set your dev project
firebase use lantern-app-dev
# Deploy functions
firebase deploy --only functions
# Verify deployment
firebase functions:list
# Check logs
firebase functions:logStep 2: Deploy to Firebase Production
# IMPORTANT: Verify all tests pass in dev first!
# Switch to production
firebase use lantern-app-prod
# Deploy functions
firebase deploy --only functions
# Verify deployment
firebase functions:list --project lantern-app-prod
# Check logs
firebase functions:log --project lantern-app-prodStep 3: Deploy Frontend
# The fix to public/_redirects and vite.config.mjs will be deployed automatically
# when you deploy to Cloudflare Pages
# For dev:
npm run build
# Deploy dist/ to Cloudflare Pages (dev branch)
# For production:
npm run build
# Deploy dist/ to Cloudflare Pages (main branch)Verification Checklist
After deployment, verify:
- [ ] Form at
#/feedbackloads without errors - [ ] Can submit feature request
- [ ] GitHub issue created with correct labels
- [ ] Discord notification sent (if configured)
- [ ] Service worker registers (DevTools > Application)
- [ ] No "MIME type" errors in console
- [ ] Rate limiting works (5 requests per 24 hours)
- [ ] Duplicate detection shows similar requests
- [ ] Anonymous submission option works
- [ ] Mobile view works and is responsive
Troubleshooting
Still Getting 500 Error on Form Submission
Check:
Are environment variables set correctly?
bashfirebase functions:config:getShould output:
json{ "github": { "token": "ghp_...", "repo": "cattreedev/lantern_app" }, "discord": { "webhook_url": "https://discord.com/api/webhooks/..." } }Check function logs for specific error:
bashfirebase functions:logVerify GitHub token is valid:
- Token must have
reposcope - Token must not be expired
- Token must have access to the repository
- Token must have
Verify GitHub repository is correct:
- Format:
owner/repo(e.g.,cattreedev/lantern_app) - Repository must be accessible with the provided token
- Format:
Service Worker Still Not Registering
Check:
- Hard refresh the page:
Ctrl+Shift+RorCmd+Shift+R - Clear all caches: DevTools > Application > Storage > Clear site data
- Check Network tab:
/sw.jsshould return 200 withapplication/javascriptMIME type - Check Console for any error messages
- Verify
_redirectsfile has the SW bypass rule:/sw.js /sw.js 200!
Duplicate Detection Not Working
Check:
Is
checkDuplicatesfunction deployed?bashfirebase functions:list | grep checkDuplicatesAre there existing feature requests in Firestore?
- Check Firebase Console > Firestore >
featureRequestscollection - The collection must exist and have documents
- Check Firebase Console > Firestore >
Check browser console for errors
Verify user is authenticated before submitting
Discord Webhook Not Sending
Check:
Is webhook URL configured?
bashfirebase functions:config:get | grep discordIs webhook URL still valid?
- Test webhook:
curl -X POST <webhook_url> -d '{"content":"test"}'
- Test webhook:
Check function logs for Discord error:
bashfirebase functions:log | grep -i discord
Environment Configuration Reference
For Development (local .runtimeconfig.json)
{
"github": {
"token": "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",
"repo": "cattreedev/lantern_app"
},
"discord": {
"webhook_url": "https://discord.com/api/webhooks/..."
}
}For Production (Firebase Functions Config)
firebase use lantern-app-prod
firebase functions:config:set \
github.token="ghp_YOUR_PROD_TOKEN" \
github.repo="cattreedev/lantern_app" \
discord.webhook_url="https://discord.com/api/webhooks/PROD_URL"Security Notes
⚠️ CRITICAL:
- Never commit
.runtimeconfig.jsonto git (already in.gitignore) - Never hardcode tokens in source code
- GitHub token should have minimal scope (
repoonly) - Discord webhook URL should be kept secret
- Rotate tokens if compromised
Next Steps
- ✅ Deploy functions to dev and test
- ✅ Verify form submission works end-to-end
- ✅ Deploy functions to production
- ✅ Deploy frontend with service worker fixes
- ⏳ Optional: Set up Cloud Run logging for better debugging
Cloud Run Logging (Optional)
If you want advanced logging and monitoring:
- Enable Cloud Logging in Google Cloud Console
- Configure Firebase Functions to use Cloud Logging
- Set up alerts for function errors
Reference: Cloud Functions Logging Guide
Support & Questions
- Function errors? Check:
firebase functions:log --tail - Service worker issues? Check: DevTools > Application > Service Workers
- GitHub API issues? Test token:
curl -H "Authorization: token ghp_xxx" https://api.github.com/user - Discord issues? Test webhook:
curl -X POST <webhook_url> -d '{"content":"test"}'