Prerequisites
- Python 3.x and
pip - A running MongoDB instance (local or cloud)
Setup
Get the server files
Clone the repository or download the
server/ directory from the Wordgrid source.Install dependencies
| Package | Purpose |
|---|---|
flask | HTTP server and routing |
flask-cors | Cross-Origin Resource Sharing support |
pymongo | MongoDB client |
python-dotenv | Loads environment variables from .env |
Create your .env file
Copy the example file and fill in your values:Then edit
.env with your MongoDB connection string and preferred port. See Configuration for all available variables.Server behaviour
Host and port — the server always binds to0.0.0.0, making it reachable on all network interfaces. The default port is 5000.
True. Flask debug mode enables the interactive debugger and auto-reloads on code changes.
flask_cors.CORS(app). All origins are permitted by default, which allows the frontend to call the API from any domain.
MongoDB collection — scores are stored in a collection named leaderboard within the database specified in your MONGO_URI. The database name is taken from the URI path (e.g., mongodb://localhost:27017/wordgrid uses the wordgrid database).
API endpoints
| Method | Path | Description |
|---|---|---|
GET | /leaderboard/<date> | Returns all scores for the given date (format: YYYY-MM-DD), sorted ascending by score. |
POST | /leaderboard | Submits a new score. Expects JSON body with name (string), score (integer), and date (string). |
Production deployment
For production, use a WSGI server such as Gunicorn instead ofpython main.py:
The server runs on
0.0.0.0 by default. If you expose it directly to the internet, ensure your firewall and MongoDB instance are configured appropriately. Consider placing the server behind a reverse proxy such as Nginx or Caddy.