Prerequisites
- A Heroku account (free tier available)
- Heroku CLI installed
- Git installed and repository initialized
- Yahoo Developer application configured
Procfile Configuration
The application includes aProcfile that tells Heroku how to run the app:
- Uses Gunicorn as the production WSGI server (instead of Flask’s development server)
- Runs the Flask app defined in
main.pyas the variableapp - Automatically binds to Heroku’s dynamically assigned port
Gunicorn is included in
requirements.txt and is production-ready, unlike Flask’s built-in development server.Deployment Steps
Install Heroku CLI
Login to Heroku
Authenticate with your Heroku account:This will open a browser window for authentication.
Create Heroku Application
Create a new Heroku app:Or let Heroku generate a random name:Note the app URL provided (e.g.,
https://your-fantasy-basketball-app.herokuapp.com).Configure Environment Variables
Set all required environment variables on Heroku:Verify your configuration:
Update Yahoo OAuth Callback
In your Yahoo Developer application settings, update the Redirect URI:
The application hardcodes HTTPS for OAuth callbacks in production (see
main.py:409):Deploy to Heroku
Ensure all changes are committed to Git:Deploy to Heroku:Or if your branch is named
master:Production Configuration
Session Security
The application configures Flask sessions for production:Protects against CSRF attacks while allowing normal navigation
Set to
True if you want to enforce HTTPS-only cookies (recommended for production)Session expires after 60 minutes (3600 seconds) of inactivity
OAuth Configuration
Yahoo OAuth is configured with production endpoints:Monitoring and Logs
View Application Logs
Check Dyno Status
Restart Application
Troubleshooting
Application crashes on startup
Application crashes on startup
Check logs for errors:Common issues:
- Missing environment variables
- Dependency installation failures
- Port binding errors (Heroku assigns the port automatically)
OAuth redirect fails
OAuth redirect fails
Verify:
- Yahoo app Redirect URI exactly matches:
https://your-app.herokuapp.com/callback - Environment variables are set correctly:
heroku config - Client ID and Secret are correct
Yahoo API rate limits
Yahoo API rate limits
Yahoo Fantasy API has rate limits. If you hit them:
- Implement caching for frequently accessed data
- Add retry logic with exponential backoff
- Monitor your API usage patterns
Session expires too quickly
Session expires too quickly
Increase the session lifetime in Then redeploy the application.
main.py:Updating Your Deployment
When you make changes to the code:Performance Optimization
Enable Heroku Dyno Autoscaling
For high-traffic periods:Add Redis Caching
Consider adding Heroku Redis for session storage and API caching:Security Best Practices
- Use strong, randomly generated
FLASK_SECRET_KEY - Rotate OAuth credentials regularly
- Enable two-factor authentication on your Heroku account
- Review Heroku security best practices at devcenter.heroku.com/categories/security
- Consider enabling
SESSION_COOKIE_SECURE=Truefor HTTPS-only cookies
Next Steps
Environment Variables
Complete reference for all configuration options
Local Development
Set up a development environment