Refactor bot server setup to use Waitress for production; fallback to Flask dev server for local development. Added timeout to HTTP requests in Fun and Test cogs. Improved error handling for missing environment variables. Enhanced secret key management in Flask app. Added request timeout configuration. Introduced new experimental features including user profile and balance cards, and a Tic-Tac-Toe game with Minimax AI. Addressed various database and security issues, and improved code quality across multiple files.
This commit is contained in:
@@ -144,4 +144,45 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
||||
|
||||
For support, please contact [yourname@example.com](mailto:yourname@example.com).
|
||||
|
||||
Happy Coding!
|
||||
Happy Coding!
|
||||
|
||||
---
|
||||
|
||||
## Deployment (Web UI)
|
||||
|
||||
This project includes a small Flask-based web UI used for OAuth flows and guild management. The development server is fine for local testing, but for production use you should run the app under a WSGI server such as `waitress` or `gunicorn`.
|
||||
|
||||
Recommended steps to serve the web UI with `waitress`:
|
||||
|
||||
1. Install dependencies (includes `waitress`):
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
2. Set the required environment variables (example `.env`):
|
||||
```env
|
||||
# Bot and web settings
|
||||
TOKEN=your_bot_token_here
|
||||
DISCORD_CLIENT_ID=your_client_id
|
||||
DISCORD_CLIENT_SECRET=your_client_secret
|
||||
DISCORD_REDIRECT_URI=https://yourdomain.com/callback
|
||||
|
||||
# Flask session secret (must be set in production)
|
||||
SECRET_KEY=replace_with_a_secure_random_value
|
||||
|
||||
# Optional runtime
|
||||
START_WEB=1 # set to 1 if you want the bot process to spawn the web UI
|
||||
REQUEST_TIMEOUT=10 # default HTTP timeout in seconds for external requests
|
||||
```
|
||||
|
||||
3. Run the web app using `waitress` (example):
|
||||
```bash
|
||||
python -m waitress --host=0.0.0.0 --port=5000 web.app:app
|
||||
```
|
||||
|
||||
Notes:
|
||||
- If you set `START_WEB=1`, `bot_development.py` will spawn the web UI when the bot starts. This is convenient for small deployments but consider running the web UI in its own process or container for reliability and easier scaling.
|
||||
- Never run the Flask development server (app.run) in production.
|
||||
- Ensure `SECRET_KEY` is kept secret and not committed to source control. Use a secure random value like `openssl rand -hex 32`.
|
||||
|
||||
If you want, I can add a small `Procfile` and Dockerfile snippet for deployment — tell me which target (Heroku, Docker Compose, or Kubernetes) you prefer.
|
||||
Reference in New Issue
Block a user