TypeScript WebSocket server for a fair crash game (Aviator-style) with Telegram auth, PostgreSQL persistence, and Redis pub/sub.
- Server-authoritative game loop (betting → flying → crash)
- Telegram Web App
initDatavalidation - Prisma + PostgreSQL for users, bets, sessions, chat
- Configurable crash-point distribution via Redis key
crashChances
src/
config.ts # ports, timings, default crash chances
index.ts # WebSocket server entry
types.ts # shared TypeScript types
controllers/ # WebSocket message handlers
services/ # game engine
utils/ # Telegram auth helpers
redis/ # ioredis-xyz client, keys, memory fallback
prisma/ # schema and migrations
npm install
cp .env.example .env
npx prisma generate
npx prisma migrate deploynpm run ws # development (tsx)
npm run build && npm start| Variable | Description |
|---|---|
DATABASE_URL |
PostgreSQL connection string |
BOT_TOKEN |
Telegram bot token for initData validation |
ADMIN_BOT_TOKEN |
Optional second bot token |
REDIS_URL |
Redis URL (redis://localhost:6379) or memory:// for in-memory |
REDIS_MEMORY |
Set true to use in-memory Redis fallback |
WS_PORT |
WebSocket port (default 4001) |
ALLOW_DEV_AUTH |
Set true only for local testing without Telegram |
Client → server: auth, bet, cashout, chat-message
Server → client: auth-success, session-history, balance-update, sync, game-start, game-flying, game-crash
The previous Next.js frontend contained hardcoded ngrok tunnel URLs in TON Connect config — removed during cleanup. Dev auth bypass now requires ALLOW_DEV_AUTH=true.