Skip to content

Latest commit

 

History

History
133 lines (88 loc) · 3.38 KB

File metadata and controls

133 lines (88 loc) · 3.38 KB

API Service

Main backend API service for the CORE game website.

Overview

This NestJS service serves as the primary backend, handling:

  • User authentication and management
  • Team and event/tournament management
  • Match results and statistics
  • Database operations (PostgreSQL)
  • RabbitMQ microservice communication

Getting Started

Prerequisites

Install pnpm:

corepack enable && corepack prepare pnpm@latest --activate

or

brew install pnpm

Installation & Setup

  1. Install dependencies:

    pnpm install
  2. Set up environment variables:

    cp .env.example .env

    Edit .env.local with your configuration (see Environment Variables below).

  3. Run database migrations:

    pnpm migration:run-local
  4. Run development server:

    pnpm start:dev

Production

  • Build: pnpm build
  • Start: pnpm start:prod

Environment Variables

Database (Required)

  • DB_HOST - PostgreSQL host
  • DB_PORT - PostgreSQL port
  • DB_USER - Database username
  • DB_PASSWORD - Database password
  • DB_NAME - Database name
  • DB_SCHEMA - Database schema
  • DB_URL - Alternative database connection URL overwrites the other database connection variables
  • DB_SSL_REQUIRED - Enable SSL connection (true/false)

External Services (Required)

  • RABBITMQ_URL - RabbitMQ connection URL
  • API_SECRET_ENCRYPTION_KEY - Key for encrypting sensitive data

Optional

  • PORT - Server port (default: 4000)
  • NODE_ENV - Environment (development/production)

Database Management

Migrations

  • Generate: pnpm migration:generate migration_name Compares your current TypeScript entities with the database and automatically generates the necessary SQL (e.g., adding or removing columns). Use this for most schema changes.
  • Create: pnpm migration:create migration_name Creates an empty migration template. Use this only for manual SQL changes (e.g., seeding data, creating complex views, or custom indexes) that TypeORM cannot detect automatically.
  • Run: pnpm migration:run-local (local) / pnpm migration:run (production)
  • Revert: pnpm migration:revert-local (local) / pnpm migration:revert (production)

Seeding

  • Seed Users and Teams: pnpm seed:users <eventId> Generates 90 users and 30 teams (3 members each) and assigns them to the specified event. This is useful for testing group phases and bracket logic.

API Documentation

When running in development mode, Swagger documentation is available at: http://localhost:4000/api

Architecture

This service runs as both:

  • REST API - HTTP endpoints for frontend communication
  • Microservice - RabbitMQ message consumer for:
    • game_results - Match result processing
    • github-service-results - GitHub operation results

Environment Variables

GitHub OAuth (Required)

  1. Go to GitHub → Settings → Developer settings → OAuth Apps
  2. Register a new OAuth app
  3. Set Authorization callback URL: http://localhost:4000/auth/github/callback
  4. Add Client ID and Secret to .env.local

42 School OAuth (Optional)

For testing account linking functionality:

  1. Go to 42 School → Settings → API → Applications
  2. Create a new application
  3. Set Redirect URI: http://localhost:4000/auth/42/callback
  4. Add Client ID and Client Secret to .env.local