Skip to content
This repository was archived by the owner on May 13, 2026. It is now read-only.

Repository files navigation

Community Leaderboard Server

A high-performance Node.js + Express backend that aggregates posts from multiple communities, calculates weighted scores, and builds a live leaderboard using SQLite.


Features

  • Auto-fetch posts from configured communities
  • Custom score calculation (score × 3.14)
  • Live aggregated leaderboard per author
  • SQLite database with WAL mode
  • Auto-refresh every 70 seconds
  • Automatic backups every 6 hours
  • Author tracking + eviction system
  • Secure admin API with secret auth
  • Security hardening (Helmet, CORS, rate limits)

Project Structure

.
├── server.js
├── leaderboard.db
├── backups/
├── .env
└── public/

Environment Variables

PORT=3001
DB_PATH=./leaderboard.db
ADMIN_SECRET=your_super_secure_admin_secret
COMMUNITY=community1,community2
API_BASE_URL=https://example.com/api/posts
X_API_KEY=your_key
X_API_PLATFORM=your_platform
X_API_SECRET=your_secret
X_XSRF_TOKEN=your_token
CORS_ORIGINS=http://localhost:3000,https://yourdomain.com
BACKUP_DIR=./backups

Running the Server

node server.js

Dev mode:

npx nodemon server.js

API Endpoints

GET /api/leaderboard

Returns ranked authors by score.
[
  {
    "author": "user123",
    "original_score": 120,
    "calculated_score": 377,
    "post_count": 15,
    "last_active_ago": "2 hours ago"
  }
]

GET /api/stats

{
  "totalPosts": 1200,
  "totalAuthors": 85,
  "authorCap": 500
}

Admin Header

X-Admin-Secret: your_secret
  • GET /api/authors
  • POST /api/refresh
  • POST /api/reset
  • POST /api/nuke
  • POST /api/backup
  • /api/backup/download/db
  • /api/backup/download/json

Scoring Logic

calculated_score = ceil(score_up × 3.14)

Security

  • Helmet HTTP headers
  • Rate limiting (public + admin)
  • CORS whitelist support
  • Admin secret authentication
  • Request size limits

Backups

  • Auto backup every 6 hours
  • Keeps last 10 backups
  • Exports authors to JSON

Notes

  • Requires valid upstream API credentials
  • Uses SQLite WAL mode
  • Auto-refresh every 70 seconds

License

This project is licensed under the GNU General Public License v3.0 (GPL-3.0).

You are free to use, modify, and distribute this software under the terms of the GPL-3.0 license, provided that any derivative work is also distributed under the same license.

Full license text available here:
https://www.gnu.org/licenses/gpl-3.0.en.html

Source Code Repository:
https://github.com/Riotcoke123/Community-Leaderboard-Server

This software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability arising from the use of this software.