Overview
The Playground project is configured for seamless deployment on Netlify, a modern hosting platform for static sites and serverless functions. The deployment is automated through Git integration and configured via thenetlify.toml file.
Netlify Configuration
The project uses the following Netlify configuration:Configuration Breakdown
Build Settings
- functions: Specifies that serverless functions are located in the
netlify/functionsdirectory
Functions Settings
- node_bundler: Uses
esbuildfor fast, efficient bundling of Node.js functions- esbuild is significantly faster than webpack
- Automatically handles dependencies and tree-shaking
- No additional configuration needed
Scheduled Functions
- enviar-notificaciones: A scheduled function that runs hourly
- Schedule:
0 */1 * * *(every hour at minute 0) - Purpose: Sends daily reminder notifications to users about their work schedules and lunch assignments
- Schedule:
The cron expression
0 */1 * * * means the function runs at the start of every hour (00:00, 01:00, 02:00, etc.).Deployment Methods
Method 1: Automatic Deployment via Git
The recommended approach is connecting your repository to Netlify for automatic deployments.Initial Setup
-
Create a Netlify Account
- Go to netlify.com
- Sign up or log in with your Git provider (GitHub, GitLab, or Bitbucket)
-
Import Repository
- Click “Add new site” → “Import an existing project”
- Connect your Git provider
- Select the Playground repository
-
Configure Build Settings
- Base directory: Leave empty (root of repository)
- Build command: Leave empty (no build step required)
- Publish directory:
.or leave empty (static files in root)
-
Add Environment Variables
Navigate to Site settings → Environment variables and add:
- Deploy
- Click “Deploy site”
- Netlify will build and deploy your site
- You’ll receive a unique URL (e.g.,
https://random-name-123.netlify.app)
Continuous Deployment
Once connected:- Production: Every push to
mainbranch triggers a production deployment - Preview: Pull requests automatically get preview deployments
- Rollback: Easy one-click rollback to previous deployments in Netlify dashboard
Method 2: Manual Deployment via Netlify CLI
For manual deployments or testing:1. Install Netlify CLI
2. Login to Netlify
3. Initialize Site (First Time)
4. Deploy
Draft Deploy (for testing):Method 3: Drag and Drop
For quick deployments without Git:- Go to app.netlify.com/drop
- Drag your project folder into the drop zone
- Netlify deploys instantly
This method doesn’t support serverless functions or scheduled functions. Use Git integration or CLI for full functionality.
Scheduled Functions
Notification Function
Theenviar-notificaciones function is the core scheduled task:
Purpose: Sends personalized notifications to users about:
- Tomorrow’s work shift schedule
- Shift time ranges
- Lunch availability and timing
- Retrieves current time in Colombia timezone
- Queries Firebase for users with notifications enabled
- For each user, checks if their scheduled notification time matches
- Fetches user’s shift data from Firebase Realtime Database
- Determines lunch assignment based on shift
- Sends personalized push notification via Firebase Cloud Messaging
- Time zone aware (America/Bogota)
- Handles multiple shift types (T1-T6, TP, TSAN)
- Maps shift variations to lunch schedules
- Graceful error handling per user
- Detailed logging for debugging
Cron Schedule Syntax
The cron expression format used by Netlify:0 */1 * * *
- Minute:
0(at the start of the hour) - Hour:
*/1(every hour) - Day of month:
*(every day) - Month:
*(every month) - Day of week:
*(every day of the week)
Custom Domain Setup
Adding a Custom Domain
- Go to Site settings → Domain management
- Click “Add custom domain”
- Enter your domain name
- Follow DNS configuration instructions
DNS Configuration
Add these records to your DNS provider: Option 1: CNAME (subdomain)Netlify automatically provisions and renews SSL certificates for custom domains via Let’s Encrypt.
Environment Variables
Required Variables
| Variable | Description | Example |
|---|---|---|
FIREBASE_SERVICE_ACCOUNT | Firebase service account JSON | {"type":"service_account",...} |
FIREBASE_DATABASE_URL | Firebase Realtime Database URL | https://project.firebaseio.com |
Setting Environment Variables
Via Netlify Dashboard:- Site settings → Environment variables
- Click “Add a variable”
- Enter key and value
- Choose scope (All scopes recommended)
Deployment Checklist
Before deploying to production:- All environment variables configured
- Firebase project set up with correct permissions
- Authentication rules configured in Firebase
- Database security rules reviewed
- Service account has necessary Firebase permissions
- Scheduled function tested locally with
netlify dev - Push notification permissions granted in browser
- Custom domain configured (if applicable)
- SSL certificate active
Monitoring and Logs
Function Logs
View logs for scheduled functions:- Netlify Dashboard → Functions
- Click on
enviar-notificaciones - View execution logs and errors
Deploy Logs
View build and deploy logs:- Netlify Dashboard → Deploys
- Click on any deploy
- View detailed logs
Performance Optimization
Asset Optimization
Netlify automatically:- Compresses images
- Minifies CSS and JavaScript
- Enables HTTP/2
- Provides global CDN distribution
Function Optimization
Theesbuild bundler provides:
- Fast cold starts
- Efficient code splitting
- Tree shaking for smaller bundles
- Native ESM support
Troubleshooting
Function Execution Errors
Problem: Scheduled function fails Check:- Environment variables are correctly set
- Firebase service account has admin permissions
- Database rules allow server-side access
- Function logs for specific error messages
Build Failures
Problem: Deployment fails Check:- All dependencies in
package.json - No syntax errors in JavaScript files
- File paths are correct (case-sensitive on Netlify)
Firebase Connection Issues
Problem: Cannot connect to Firebase from functions Solution: VerifyFIREBASE_SERVICE_ACCOUNT is valid JSON and includes all required fields.
Next Steps
- Review local development setup
- Understand project dependencies
- Set up Firebase Analytics for usage tracking
- Configure Netlify Forms for user feedback
