Skip to content

Missile-Wars-Revival/backend

Repository files navigation

Missile Wars Backend

The official backend server for Missile Wars, developed by longtimeno-c.

⚠️ License & Usage Notice

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0). This means:

  • ✅ You can view and fork this code
  • ✅ You can use this code for personal projects
  • ✅ You can modify the code
  • ❌ You cannot use this code in closed-source commercial projects
  • ❗ Any modifications or usage of this code must be made open source
  • ❗ You must include the original license and copyright notice

For the full license text, see LICENSE

Copyright (c) 2024 longtimeno-c. All rights reserved.

🚀 Features

  • Real-time game state management using WebSockets (Middle Earth Library)
  • Secure authentication system
  • Push notifications via Firebase and expo notifications
  • Email notification system
  • Database integration with Prisma

📋 Prerequisites

  • Node.js (v16.x or higher)
  • npm (v8.x or higher)
  • PostgreSQL database
  • Firebase account for notifications and real time messaging
  • SMTP server access for emails

🛠️ Setup

1. Environment Configuration

Create an .env file in the root directory:

# Server Configuration
NODE_ENV="development"
JWT_SECRET="your-secure-secret-here"  # Generate a secure random string
VERBOSE_MODE="ON"
DISABLE_AUTH="OFF"
PORT=3000

# Database
DATABASE_URL="postgresql://user:password@localhost:5432/dbname"

# Email Configuration
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_SECURE=false
EMAIL_USER="your-email@domain.com"
EMAIL_PASS="your-app-specific-password"
EMAIL_FROM="noreply@yourdomain.com"

# WebSocket Configuration (Middle Earth)
WS_PORT=3001
WS_HEARTBEAT_INTERVAL=30000

2. Firebase Setup

  1. Create a Firebase project at Firebase Console
  2. Download your Firebase service account credentials
  3. Rename the credentials file to firebasecred.json and place it in the project root
  4. This enables real-time push notifications for android devices, profile picture storage and secure firebase authenticaiton / account management.

🚀 Running the Server

Install Dependencies

npm install

Development Mode

npm run dev

Production Mode

npm run build
npm start

� AWS Elastic Beanstalk Deployment

Prerequisites

  • AWS CLI installed and configured
  • EB CLI installed (pip install awsebcli)

Initialize Elastic Beanstalk Application

eb init

Follow the prompts to select your region, application name, and platform.

Create Environment

eb create [environment-name]

Creates a new Elastic Beanstalk environment. Replace [environment-name] with your desired environment name (e.g., production, staging).

Configure Environment Variables

Elastic Beanstalk does not automatically upload your local .env file. Set variables on the environment instead.

# Set variables manually
eb setenv KEY=value OTHER=value

Import all variables from .env

git add -f .env
# Verify and select an environment
eb list
eb use your-env-name
eb printenv --environment your-env-name

Deploy Code

Important: Build the application locally before deploying:

npm run build

This ensures the dist/ directory is created and included in the deployment bundle. The dist/ folder contains the compiled JavaScript files and is not ignored in version control.

eb deploy --staged

Deploys your backend code to the active Elastic Beanstalk environment.

Check Environment Status

eb status

Displays the current status of your Elastic Beanstalk environment.

View Application Logs

eb logs

Retrieves and displays the logs from your Elastic Beanstalk environment.

List Environments

eb list

Lists all environments for the current application.

Switch Environment

eb use [environment-name]

Switches to a different environment as the active deployment target.

Terminate Environment

eb terminate [environment-name]

Terminates the specified Elastic Beanstalk environment. Use with caution as this will delete the environment and all associated resources.

Open Application in Browser

eb open

Opens the URL of your Elastic Beanstalk application in your default web browser.

�🗄️ Database Management (Prisma)

Schema Management

# Pull current database schema
npx prisma db pull 

# Generate Prisma Client
npx prisma generate

# Open Prisma Studio (GUI database editor)
npx prisma studio

Schema Migrations

# Create a new migration
npx prisma migrate dev --create-only

# Apply migration
npx prisma migrate dev

📦 Data Migration Tools

Export Database

npx ts-node export-script.ts

Import Database

  1. Update your .env file with new database credentials
  2. Update schema if necessary
  3. Run import script:
npx ts-node import-script.ts

🤝 Contributing

Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

📝 Support

For support, please open an issue in the GitHub repository or contact me on X.

✨ Acknowledgments

  • Middle Earth Library
  • Firebase
  • Prisma Team
  • Expo Team

About

The Backend repo for the Missile Wars revival project

Resources

License

Stars

Watchers

Forks

Contributors