Skip to content

Commit af85f23

Browse files
committed
feat: Update environment configuration and scripts for MongoDB integration and version bump to 1.2.0
1 parent aee15d5 commit af85f23

9 files changed

Lines changed: 161 additions & 19 deletions

File tree

‎.env.example‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,36 @@
1+
# ==============================================
2+
# Wizard Tracker Environment Configuration
3+
# ==============================================
4+
# Copy this file to .env and run: npm run setup-env
5+
16
# Frontend Configuration
27
# App version for build information
3-
VITE_APP_VERSION=1.1.11.2
8+
VITE_APP_VERSION=1.2.0
9+
VITE_BUILD_DATE=
410

511
# Backend Configuration
12+
# ==============================================
13+
614
# MongoDB Connection
7-
MONGO_URI=mongodb://localhost:27017/wizard-tracker
15+
# For local development: mongodb://localhost:27017/wizard-tracker
16+
# For Docker: mongodb://mongodb:27017/wizard-tracker
17+
MONGO_URI=mongodb://mongodb:27017/wizard-tracker
818

9-
# JWT Secret (generate a secure random string for production)
10-
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
19+
# JWT Secret - DO NOT COMMIT REAL VALUES TO GIT
20+
# Generate new secret on each deployment for security
21+
# Use: npm run setup-env
22+
JWT_SECRET=CHANGE_ME_ON_DEPLOYMENT
1123

12-
# Node Environment
24+
# Server Configuration
1325
NODE_ENV=development
26+
PORT=5000
27+
28+
# Upload Service Settings
29+
# ==============================================
30+
UPLOAD_CONCURRENCY=5
31+
REPLACE_EXISTING_GAMES=false
32+
33+
# Docker MongoDB Admin Interface
34+
# ==============================================
35+
ME_CONFIG_BASICAUTH_USERNAME=admin
36+
ME_CONFIG_BASICAUTH_PASSWORD=admin123

‎.github/workflows/docker-build.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
build-and-push:
1010
runs-on: ubuntu-latest
1111
env:
12-
VITE_APP_VERSION: "1.1.11.2"
12+
VITE_APP_VERSION: "1.2.0"
1313

1414
steps:
1515
- name: Checkout repository
@@ -31,5 +31,5 @@ jobs:
3131
push: true
3232
tags: beerejustin/wizard-frontend:latest
3333
build-args: |
34-
VITE_APP_VERSION=1.1.11.2
34+
VITE_APP_VERSION=1.2.0
3535
VITE_BUILD_DATE=${{ github.event.head_commit.timestamp }}

‎README.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# KeepWiz
22

3-
![Version](https://img.shields.io/badge/version-1.1.11.2-blue)
3+
![Version](https://img.shields.io/badge/version-1.2.0-blue)
44
![License](https://img.shields.io/badge/license-MIT-green)
55
![Docker](https://img.shields.io/badge/docker-ready-brightgreen)
66

@@ -26,10 +26,13 @@ Before running the application, set up your environment variables:
2626
cp .env.example .env
2727
```
2828

29-
2. Update the values in `.env` with your backend configuration:
29+
2. Generate secure secrets and configure the environment:
3030

31-
- `MONGO_URI`: Your MongoDB connection string
32-
- `JWT_SECRET`: Your JWT secret key for authentication
31+
```bash
32+
npm run setup-env
33+
```
34+
35+
This will automatically generate a secure JWT secret and prepare your environment for deployment.
3336

3437
## Installation & Usage
3538

‎docker-compose.yml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ services:
33
build:
44
context: ./frontend
55
args:
6-
VITE_APP_VERSION: ${VITE_APP_VERSION:-1.1.11}
7-
VITE_BUILD_DATE: ${VITE_BUILD_DATE}
6+
VITE_APP_VERSION: ${VITE_APP_VERSION:-1.2.0}
7+
VITE_BUILD_DATE: ${VITE_BUILD_DATE:-$(date -u +"%Y-%m-%dT%H:%M:%SZ")}
88
ports:
99
- "8088:80" # Host:Container
1010
depends_on:
@@ -19,7 +19,7 @@ services:
1919
- MONGO_URI=${MONGO_URI:-mongodb://mongodb:27017/wizard-tracker}
2020
- JWT_SECRET=${JWT_SECRET:-your-super-secret-jwt-key-change-this-in-production}
2121
- NODE_ENV=${NODE_ENV:-production}
22-
- PORT=5000
22+
- PORT=${PORT:-5000}
2323
depends_on:
2424
- mongodb
2525

@@ -39,8 +39,8 @@ services:
3939
environment:
4040
- ME_CONFIG_MONGODB_URL=mongodb://mongodb:27017/wizard-tracker
4141
- ME_CONFIG_MONGODB_SERVER=mongodb
42-
- ME_CONFIG_BASICAUTH_USERNAME=admin
43-
- ME_CONFIG_BASICAUTH_PASSWORD=admin123
42+
- ME_CONFIG_BASICAUTH_USERNAME=${ME_CONFIG_BASICAUTH_USERNAME:-admin}
43+
- ME_CONFIG_BASICAUTH_PASSWORD=${ME_CONFIG_BASICAUTH_PASSWORD:-admin123}
4444
- ME_CONFIG_SITE_BASEURL=/
4545
depends_on:
4646
- mongodb

‎frontend/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "frontend",
33
"private": true,
4-
"version": "1.1.11.2",
4+
"version": "1.2.0",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

‎frontend/public/service-worker.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Service Worker for KeepWiz PWA - Automatic Updates
2-
const CACHE_NAME = "keep-wiz-v1.1.11.2" // Increment version for updates
2+
const CACHE_NAME = "keep-wiz-v1.2.0" // Increment version for updates
33
const urlsToCache = [
44
"/",
55
"/index.html",

‎frontend/src/service-worker.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Service Worker for KeepWiz PWA
2-
const CACHE_NAME = "keep-wiz-v1.1.11.2"
2+
const CACHE_NAME = "keep-wiz-v1.2.0"
33
const urlsToCache = ["/", "/index.html", "/manifest.json", "/icons/pwa-192x192.png", "/icons/pwa-512x512.png"]
44

55
// Install event - cache assets

‎package.json‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "wizard-tracker",
3+
"version": "1.2.0",
4+
"description": "Card game score tracking application with React frontend and MongoDB backend",
5+
"scripts": {
6+
"setup-env": "node scripts/setup-env.js",
7+
"update-secrets": "node scripts/setup-env.js",
8+
"dev": "npm run setup-env && docker compose up -d",
9+
"start": "docker compose up -d",
10+
"stop": "docker compose down",
11+
"restart": "npm run stop && npm run start",
12+
"logs": "docker compose logs -f",
13+
"build": "docker compose build",
14+
"clean": "docker compose down -v && docker system prune -f"
15+
},
16+
"repository": {
17+
"type": "git",
18+
"url": "https://github.com/jkrumboe/wizard-tracker.git"
19+
},
20+
"keywords": [
21+
"card-game",
22+
"score-tracking",
23+
"react",
24+
"mongodb",
25+
"docker"
26+
],
27+
"author": "jkrumboe",
28+
"license": "MIT",
29+
"engines": {
30+
"node": ">=18.0.0"
31+
}
32+
}

‎scripts/setup-env.js‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Environment Setup Script
5+
* Generates secure JWT secret and updates .env file
6+
* Run this script on each deployment or update
7+
*/
8+
9+
const fs = require('fs');
10+
const path = require('path');
11+
const crypto = require('crypto');
12+
13+
const ENV_PATH = path.join(__dirname, '..', '.env');
14+
15+
function generateJWTSecret() {
16+
return crypto.randomBytes(64).toString('hex');
17+
}
18+
19+
function updateEnvFile() {
20+
try {
21+
// Check if .env file exists
22+
if (!fs.existsSync(ENV_PATH)) {
23+
console.error('.env file not found at:', ENV_PATH);
24+
console.log('Please copy .env.example to .env first');
25+
process.exit(1);
26+
}
27+
28+
// Read current .env content
29+
let envContent = fs.readFileSync(ENV_PATH, 'utf8');
30+
31+
// Generate new JWT secret
32+
const newJWTSecret = generateJWTSecret();
33+
34+
// Update JWT_SECRET in the content
35+
envContent = envContent.replace(
36+
/JWT_SECRET=.*/,
37+
`JWT_SECRET=${newJWTSecret}`
38+
);
39+
40+
// Write updated content back to .env
41+
fs.writeFileSync(ENV_PATH, envContent);
42+
43+
console.log('Environment setup completed!');
44+
console.log('New JWT secret generated and updated in .env file');
45+
console.log('Make sure to restart your application to use the new secret');
46+
47+
} catch (error) {
48+
console.error('Error updating .env file:', error.message);
49+
process.exit(1);
50+
}
51+
}
52+
53+
// Add this to package.json scripts
54+
function updatePackageJson() {
55+
const packageJsonPath = path.join(__dirname, '..', 'package.json');
56+
57+
if (fs.existsSync(packageJsonPath)) {
58+
try {
59+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
60+
61+
if (!packageJson.scripts) {
62+
packageJson.scripts = {};
63+
}
64+
65+
packageJson.scripts['setup-env'] = 'node scripts/setup-env.js';
66+
packageJson.scripts['update-secrets'] = 'node scripts/setup-env.js';
67+
68+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
69+
console.log('Updated package.json with setup scripts');
70+
} catch (error) {
71+
console.log('Could not update package.json:', error.message);
72+
}
73+
}
74+
}
75+
76+
// Main execution
77+
console.log('Setting up Wizard Tracker environment...');
78+
updateEnvFile();
79+
updatePackageJson();
80+
81+
console.log('\n Next steps:');
82+
console.log('1. Run: npm run setup-env (anytime you need new secrets)');
83+
console.log('2. For Docker: docker compose down && docker compose up -d');
84+
console.log('3. For local dev: npm run dev (in frontend) and npm start (in backend)');

0 commit comments

Comments
 (0)