mirror of
https://github.com/DeNNiiInc/Connect-5.git
synced 2026-04-17 22:46:00 +00:00
Clean up deployment scripts and documentation
- Removed all unused/deprecated deployment scripts - Created single unified deploy.sh script - Added comprehensive DEPLOYMENT.md guide - Updated README.md for Supabase migration - Script prompts for project directory or uses current - Auto-detects web server (Nginx/Apache/CloudSticks) - Fully automated deployment process
This commit is contained in:
118
APACHE_FIX.md
118
APACHE_FIX.md
@@ -1,118 +0,0 @@
|
||||
# Quick Fix for CloudSticks Apache Proxy
|
||||
|
||||
## Problem
|
||||
The Node.js server is running on port 3000, but Apache is not forwarding `/api` and `/socket.io` requests to it.
|
||||
|
||||
## Solution
|
||||
|
||||
### Step 1: Enable Apache Proxy Modules
|
||||
|
||||
Run these commands on your CloudSticks server:
|
||||
|
||||
```bash
|
||||
sudo a2enmod proxy
|
||||
sudo a2enmod proxy_http
|
||||
sudo a2enmod proxy_wstunnel
|
||||
sudo a2enmod rewrite
|
||||
```
|
||||
|
||||
### Step 2: Find Your Apache Config File
|
||||
|
||||
CloudSticks likely uses one of these locations:
|
||||
```bash
|
||||
# Check which file exists:
|
||||
ls -la /etc/apache2/sites-available/connect5*
|
||||
ls -la /etc/apache2/sites-available/000-default-le-ssl.conf
|
||||
ls -la /etc/apache2/sites-available/default-ssl.conf
|
||||
```
|
||||
|
||||
### Step 3: Edit the Config File
|
||||
|
||||
```bash
|
||||
# Use nano or vi to edit (replace with your actual file):
|
||||
sudo nano /etc/apache2/sites-available/connect5.conf
|
||||
```
|
||||
|
||||
### Step 4: Add These Lines
|
||||
|
||||
Add these lines **inside** your `<VirtualHost *:443>` block (before `</VirtualHost>`):
|
||||
|
||||
```apache
|
||||
# Proxy API and Socket.io to Node.js
|
||||
ProxyPreserveHost On
|
||||
ProxyPass /api http://localhost:3000/api
|
||||
ProxyPassReverse /api http://localhost:3000/api
|
||||
ProxyPass /socket.io http://localhost:3000/socket.io
|
||||
ProxyPassReverse /socket.io http://localhost:3000/socket.io
|
||||
|
||||
# WebSocket support
|
||||
RewriteEngine On
|
||||
RewriteCond %{HTTP:Upgrade} =websocket [NC]
|
||||
RewriteRule /(.*) ws://localhost:3000/$1 [P,L]
|
||||
```
|
||||
|
||||
### Step 5: Test and Restart Apache
|
||||
|
||||
```bash
|
||||
# Test configuration
|
||||
sudo apache2ctl configtest
|
||||
|
||||
# If OK, restart Apache
|
||||
sudo systemctl restart apache2
|
||||
```
|
||||
|
||||
### Step 6: Verify It Works
|
||||
|
||||
```bash
|
||||
# Test API endpoint
|
||||
curl https://connect5.beyondcloud.technology/api/db-status
|
||||
|
||||
# Should return JSON with "connected": true
|
||||
```
|
||||
|
||||
Then visit https://connect5.beyondcloud.technology/ in your browser!
|
||||
|
||||
---
|
||||
|
||||
## Alternative: Quick .htaccess Method
|
||||
|
||||
If you can't edit the Apache config, try adding this to `.htaccess` in your project root:
|
||||
|
||||
```apache
|
||||
RewriteEngine On
|
||||
|
||||
# Proxy API requests
|
||||
RewriteCond %{REQUEST_URI} ^/api/
|
||||
RewriteRule ^api/(.*)$ http://localhost:3000/api/$1 [P,L]
|
||||
|
||||
# Proxy Socket.io requests
|
||||
RewriteCond %{REQUEST_URI} ^/socket\.io/
|
||||
RewriteRule ^socket\.io/(.*)$ http://localhost:3000/socket.io/$1 [P,L]
|
||||
```
|
||||
|
||||
**Note**: This requires `AllowOverride All` in your Apache config.
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Check if Node.js is Running
|
||||
```bash
|
||||
ps aux | grep "node server.js"
|
||||
curl http://localhost:3000/api/db-status
|
||||
```
|
||||
|
||||
### Check Apache Error Logs
|
||||
```bash
|
||||
sudo tail -f /var/log/apache2/error.log
|
||||
```
|
||||
|
||||
### Check if Modules are Enabled
|
||||
```bash
|
||||
apache2ctl -M | grep proxy
|
||||
```
|
||||
|
||||
Should show:
|
||||
- proxy_module
|
||||
- proxy_http_module
|
||||
- proxy_wstunnel_module
|
||||
@@ -1,176 +0,0 @@
|
||||
# CloudSticks Deployment Guide
|
||||
|
||||
## Quick Setup (No PM2 Required)
|
||||
|
||||
Since CloudSticks auto-deploys from GitHub, you only need to set up the database config and ensure the server is running.
|
||||
|
||||
### Option 1: Use the CloudSticks Deployment Script
|
||||
|
||||
```bash
|
||||
cd /home/github2/apps/app-connect5
|
||||
chmod +x deploy-cloudsticks.sh
|
||||
./deploy-cloudsticks.sh
|
||||
```
|
||||
|
||||
This will:
|
||||
- ✅ Install dependencies
|
||||
- ✅ Create `db.config.js` with Supabase credentials
|
||||
- ✅ Attempt to restart the server (systemd or PM2 if available)
|
||||
- ✅ Test the API endpoint
|
||||
|
||||
---
|
||||
|
||||
### Option 2: Manual Setup
|
||||
|
||||
If you prefer manual setup:
|
||||
|
||||
```bash
|
||||
cd /home/github2/apps/app-connect5
|
||||
|
||||
# Install dependencies
|
||||
npm install
|
||||
|
||||
# Create db.config.js
|
||||
cat > db.config.js << 'EOF'
|
||||
module.exports = {
|
||||
supabaseUrl: 'https://wxtirlphaphwbrgsjyop.supabase.co',
|
||||
supabaseAnonKey: 'sb_publishable_Onh4nNYCV99d2eGidQIpqA_9PBkY8zs',
|
||||
supabasePassword: 't1hWsackxbYzRIPD',
|
||||
postgresConnectionString: 'postgresql://postgres:t1hWsackxbYzRIPD@db.wxtirlphaphwbrgsjyop.supabase.co:5432/postgres'
|
||||
};
|
||||
EOF
|
||||
|
||||
# Check if server is running
|
||||
ps aux | grep "node server.js"
|
||||
|
||||
# If not running, start it
|
||||
nohup node server.js > server.log 2>&1 &
|
||||
|
||||
# Or if CloudSticks uses systemd:
|
||||
sudo systemctl restart connect5
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Verify Deployment
|
||||
|
||||
### 1. Check if Node.js is Running
|
||||
|
||||
```bash
|
||||
ps aux | grep node
|
||||
```
|
||||
|
||||
Should show `node server.js` running
|
||||
|
||||
### 2. Test API Locally
|
||||
|
||||
```bash
|
||||
curl http://localhost:3000/api/db-status
|
||||
```
|
||||
|
||||
Should return JSON with `"connected": true`
|
||||
|
||||
### 3. Test in Browser
|
||||
|
||||
Visit: https://connect5.beyondcloud.technology/
|
||||
|
||||
Check status bar shows:
|
||||
- **SQL**: Connected ✅
|
||||
- **Latency**: ~45ms
|
||||
- **Write**: Enabled ✅
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Server Not Running
|
||||
|
||||
**Start the server**:
|
||||
```bash
|
||||
cd /home/github2/apps/app-connect5
|
||||
node server.js > server.log 2>&1 &
|
||||
```
|
||||
|
||||
**Check logs**:
|
||||
```bash
|
||||
tail -f server.log
|
||||
```
|
||||
|
||||
### API Returns 404
|
||||
|
||||
**Check Apache/Nginx proxy**:
|
||||
The web server needs to proxy `/api/*` and `/socket.io/*` to `localhost:3000`
|
||||
|
||||
**For Apache**, ensure you have:
|
||||
```apache
|
||||
ProxyPass /api http://localhost:3000/api
|
||||
ProxyPassReverse /api http://localhost:3000/api
|
||||
ProxyPass /socket.io http://localhost:3000/socket.io
|
||||
ProxyPassReverse /socket.io http://localhost:3000/socket.io
|
||||
```
|
||||
|
||||
### Database Connection Fails
|
||||
|
||||
**Verify credentials**:
|
||||
```bash
|
||||
cat db.config.js
|
||||
```
|
||||
|
||||
**Test Supabase connection**:
|
||||
```bash
|
||||
node -e "const {supabase} = require('./database'); supabase.from('players').select('id').limit(1).then(console.log).catch(console.error)"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## CloudSticks-Specific Notes
|
||||
|
||||
- **Auto-Deploy**: CloudSticks automatically pulls from GitHub when you push
|
||||
- **No PM2**: CloudSticks may not have PM2 installed - use systemd or direct node
|
||||
- **Logs**: Check `server.log` for application logs
|
||||
- **Restart**: After code changes, restart the Node.js process
|
||||
|
||||
---
|
||||
|
||||
## Keep Server Running
|
||||
|
||||
### Option 1: Using nohup (Simple)
|
||||
```bash
|
||||
nohup node server.js > server.log 2>&1 &
|
||||
```
|
||||
|
||||
### Option 2: Using systemd (Recommended)
|
||||
|
||||
Create `/etc/systemd/system/connect5.service`:
|
||||
```ini
|
||||
[Unit]
|
||||
Description=Connect-5 Multiplayer Server
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=github2
|
||||
WorkingDirectory=/home/github2/apps/app-connect5
|
||||
ExecStart=/usr/bin/node server.js
|
||||
Restart=always
|
||||
Environment=NODE_ENV=production
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
Enable and start:
|
||||
```bash
|
||||
sudo systemctl enable connect5
|
||||
sudo systemctl start connect5
|
||||
sudo systemctl status connect5
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Future Updates
|
||||
|
||||
When you push to GitHub:
|
||||
1. CloudSticks auto-deploys the code
|
||||
2. Run: `./deploy-cloudsticks.sh` (or restart server manually)
|
||||
3. Verify at https://connect5.beyondcloud.technology/
|
||||
337
DEPLOYMENT.md
Normal file
337
DEPLOYMENT.md
Normal file
@@ -0,0 +1,337 @@
|
||||
# Connect-5 Production Deployment Guide
|
||||
|
||||
Complete guide for deploying Connect-5 to production with Supabase database.
|
||||
|
||||
## Quick Deploy
|
||||
|
||||
```bash
|
||||
# On your production server
|
||||
cd /path/to/Connect-5
|
||||
sudo bash deploy.sh
|
||||
```
|
||||
|
||||
The script will:
|
||||
1. ✅ Prompt for project directory (or use current)
|
||||
2. ✅ Request Supabase credentials
|
||||
3. ✅ Create `db.config.js`
|
||||
4. ✅ Install dependencies
|
||||
5. ✅ Detect and configure web server (Nginx/Apache)
|
||||
6. ✅ Start Node.js server
|
||||
7. ✅ Test endpoints
|
||||
|
||||
---
|
||||
|
||||
## Prerequisites
|
||||
|
||||
### 1. Supabase Setup
|
||||
|
||||
1. Create project at [app.supabase.com](https://app.supabase.com)
|
||||
2. Run the SQL schema from [supabase-schema-complete.sql](supabase-schema-complete.sql)
|
||||
3. Get your credentials:
|
||||
- Project URL
|
||||
- Anon/Public API key
|
||||
- Database password
|
||||
|
||||
See [SUPABASE_SETUP.md](SUPABASE_SETUP.md) for detailed instructions.
|
||||
|
||||
### 2. Server Requirements
|
||||
|
||||
- Node.js 14+ installed
|
||||
- Nginx or Apache web server
|
||||
- SSL certificate configured
|
||||
- Port 3000 available for Node.js
|
||||
|
||||
---
|
||||
|
||||
## Manual Deployment
|
||||
|
||||
If you prefer manual deployment or the script doesn't work for your environment:
|
||||
|
||||
### Step 1: Update Code
|
||||
|
||||
```bash
|
||||
cd /path/to/Connect-5
|
||||
git pull origin main
|
||||
npm install
|
||||
```
|
||||
|
||||
### Step 2: Configure Database
|
||||
|
||||
Create `db.config.js`:
|
||||
|
||||
```javascript
|
||||
module.exports = {
|
||||
supabaseUrl: 'https://your-project.supabase.co',
|
||||
supabaseAnonKey: 'your-anon-key',
|
||||
supabasePassword: 'your-db-password',
|
||||
postgresConnectionString: 'postgresql://postgres:password@db.project.supabase.co:5432/postgres'
|
||||
};
|
||||
```
|
||||
|
||||
### Step 3: Configure Web Server
|
||||
|
||||
#### For CloudSticks Nginx
|
||||
|
||||
Edit `/etc/nginx-cs/vhosts.d/app-yourproject.conf` and add inside the `server` block:
|
||||
|
||||
```nginx
|
||||
# Connect-5 API Proxy
|
||||
location /api {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Connect-5 Socket.io Proxy
|
||||
location /socket.io {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
```
|
||||
|
||||
Restart Nginx:
|
||||
```bash
|
||||
sudo systemctl restart nginx-cs
|
||||
```
|
||||
|
||||
#### For Standard Nginx
|
||||
|
||||
Add to your site config in `/etc/nginx/sites-available/yoursite`:
|
||||
|
||||
```nginx
|
||||
location /api {
|
||||
proxy_pass http://localhost:3000;
|
||||
# ... same proxy headers as above
|
||||
}
|
||||
|
||||
location /socket.io {
|
||||
proxy_pass http://localhost:3000;
|
||||
# ... same proxy headers as above
|
||||
}
|
||||
```
|
||||
|
||||
Restart:
|
||||
```bash
|
||||
sudo systemctl restart nginx
|
||||
```
|
||||
|
||||
#### For Apache
|
||||
|
||||
Enable modules:
|
||||
```bash
|
||||
sudo a2enmod proxy proxy_http proxy_wstunnel rewrite
|
||||
```
|
||||
|
||||
Add to your VirtualHost:
|
||||
```apache
|
||||
ProxyPreserveHost On
|
||||
ProxyPass /api http://localhost:3000/api
|
||||
ProxyPassReverse /api http://localhost:3000/api
|
||||
ProxyPass /socket.io http://localhost:3000/socket.io
|
||||
ProxyPassReverse /socket.io http://localhost:3000/socket.io
|
||||
|
||||
RewriteEngine On
|
||||
RewriteCond %{HTTP:Upgrade} =websocket [NC]
|
||||
RewriteRule /(.*) ws://localhost:3000/$1 [P,L]
|
||||
```
|
||||
|
||||
Restart:
|
||||
```bash
|
||||
sudo systemctl restart apache2
|
||||
```
|
||||
|
||||
### Step 4: Start Node.js Server
|
||||
|
||||
```bash
|
||||
cd /path/to/Connect-5
|
||||
nohup node server.js > server.log 2>&1 &
|
||||
```
|
||||
|
||||
Or use PM2:
|
||||
```bash
|
||||
pm2 start server.js --name connect5
|
||||
pm2 save
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Verification
|
||||
|
||||
### 1. Test API Endpoint
|
||||
|
||||
```bash
|
||||
curl https://yourdomain.com/api/db-status
|
||||
```
|
||||
|
||||
Should return:
|
||||
```json
|
||||
{
|
||||
"connected": true,
|
||||
"latency": 45,
|
||||
"writeCapable": true,
|
||||
"database": "Supabase PostgreSQL"
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Check Website
|
||||
|
||||
Visit `https://yourdomain.com/` and verify:
|
||||
- ✅ Status bar shows "Connected" (green)
|
||||
- ✅ Latency is displayed (~45ms)
|
||||
- ✅ "Write: Enabled" shows (green)
|
||||
|
||||
### 3. Test Multiplayer
|
||||
|
||||
1. Click "Multiplayer"
|
||||
2. Register a username
|
||||
3. Should see "Welcome back, [username]!"
|
||||
4. Online players list should populate
|
||||
5. Try creating/joining a game
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### API Returns 404
|
||||
|
||||
**Problem**: Web server not proxying to Node.js
|
||||
|
||||
**Solution**:
|
||||
1. Check web server config has proxy rules
|
||||
2. Restart web server
|
||||
3. Verify Node.js is running: `ps aux | grep "node server.js"`
|
||||
|
||||
### Database Disconnected
|
||||
|
||||
**Problem**: Supabase credentials incorrect
|
||||
|
||||
**Solution**:
|
||||
1. Check `db.config.js` has correct URL and key
|
||||
2. Verify credentials in Supabase dashboard
|
||||
3. Check server.log: `tail -f server.log`
|
||||
|
||||
### WebSocket Connection Failed
|
||||
|
||||
**Problem**: Proxy not configured for WebSocket upgrade
|
||||
|
||||
**Solution**:
|
||||
1. For Nginx: Add `proxy_set_header Upgrade $http_upgrade`
|
||||
2. For Apache: Add `RewriteCond %{HTTP:Upgrade} =websocket`
|
||||
3. Restart web server
|
||||
|
||||
### Node.js Server Won't Start
|
||||
|
||||
**Problem**: Port 3000 in use or database connection failed
|
||||
|
||||
**Solution**:
|
||||
1. Check port: `netstat -tlnp | grep 3000`
|
||||
2. Check logs: `tail -f server.log`
|
||||
3. Verify Supabase credentials
|
||||
4. Test database: `curl http://localhost:3000/api/db-status`
|
||||
|
||||
---
|
||||
|
||||
## CloudSticks-Specific Notes
|
||||
|
||||
CloudSticks uses custom Nginx setup:
|
||||
- Config location: `/etc/nginx-cs/`
|
||||
- Vhosts: `/etc/nginx-cs/vhosts.d/`
|
||||
- Service name: `nginx-cs`
|
||||
- Restart: `sudo systemctl restart nginx-cs`
|
||||
|
||||
The deployment script automatically detects CloudSticks and configures accordingly.
|
||||
|
||||
---
|
||||
|
||||
## Environment-Specific Configuration
|
||||
|
||||
### Development
|
||||
```bash
|
||||
npm start
|
||||
# Runs on http://localhost:3000
|
||||
```
|
||||
|
||||
### Production
|
||||
- Uses web server proxy (Nginx/Apache)
|
||||
- HTTPS enabled
|
||||
- Node.js runs in background
|
||||
- Logs to `server.log`
|
||||
|
||||
---
|
||||
|
||||
## Maintenance
|
||||
|
||||
### Update Application
|
||||
|
||||
```bash
|
||||
cd /path/to/Connect-5
|
||||
git pull origin main
|
||||
npm install
|
||||
pkill -f "node server.js"
|
||||
nohup node server.js > server.log 2>&1 &
|
||||
```
|
||||
|
||||
### View Logs
|
||||
|
||||
```bash
|
||||
# Node.js logs
|
||||
tail -f /path/to/Connect-5/server.log
|
||||
|
||||
# Nginx logs
|
||||
sudo tail -f /var/log/nginx/error.log
|
||||
|
||||
# Apache logs
|
||||
sudo tail -f /var/log/apache2/error.log
|
||||
```
|
||||
|
||||
### Restart Services
|
||||
|
||||
```bash
|
||||
# Node.js
|
||||
pkill -f "node server.js"
|
||||
cd /path/to/Connect-5
|
||||
nohup node server.js > server.log 2>&1 &
|
||||
|
||||
# Nginx (CloudSticks)
|
||||
sudo systemctl restart nginx-cs
|
||||
|
||||
# Nginx (Standard)
|
||||
sudo systemctl restart nginx
|
||||
|
||||
# Apache
|
||||
sudo systemctl restart apache2
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Security Notes
|
||||
|
||||
- `db.config.js` is in `.gitignore` (never commit credentials)
|
||||
- Use environment variables for sensitive data in production
|
||||
- Enable Supabase Row Level Security (RLS) policies
|
||||
- Keep dependencies updated: `npm audit fix`
|
||||
- Use HTTPS only (no HTTP)
|
||||
|
||||
---
|
||||
|
||||
## Support
|
||||
|
||||
For issues:
|
||||
1. Check this deployment guide
|
||||
2. Review [SUPABASE_SETUP.md](SUPABASE_SETUP.md)
|
||||
3. Check server logs
|
||||
4. Verify Supabase dashboard shows activity
|
||||
5. Test local endpoint: `curl http://localhost:3000/api/db-status`
|
||||
150
NGINX_SETUP.md
150
NGINX_SETUP.md
@@ -1,150 +0,0 @@
|
||||
# Nginx Configuration for Connect-5 on CloudSticks
|
||||
|
||||
## Quick Setup (Automated)
|
||||
|
||||
```bash
|
||||
cd /home/github2/apps/app-connect5
|
||||
sudo bash setup-nginx.sh
|
||||
```
|
||||
|
||||
That's it! The script will automatically configure everything.
|
||||
|
||||
---
|
||||
|
||||
## Manual Setup (If Needed)
|
||||
|
||||
### Step 1: Find Your Nginx Config
|
||||
|
||||
```bash
|
||||
# Find config files
|
||||
ls -la /etc/nginx/sites-available/
|
||||
ls -la /etc/nginx/conf.d/
|
||||
|
||||
# Or search for your domain
|
||||
grep -r "connect5.beyondcloud.technology" /etc/nginx/
|
||||
```
|
||||
|
||||
### Step 2: Edit the Config
|
||||
|
||||
```bash
|
||||
# Edit the config file (replace with your actual file)
|
||||
sudo nano /etc/nginx/sites-available/connect5.beyondcloud.technology
|
||||
```
|
||||
|
||||
### Step 3: Add Proxy Configuration
|
||||
|
||||
Add these `location` blocks **inside** your `server` block:
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name connect5.beyondcloud.technology;
|
||||
|
||||
# Your existing SSL and root configuration...
|
||||
|
||||
# Add these proxy configurations:
|
||||
location /api {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location /socket.io {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Step 4: Test and Reload
|
||||
|
||||
```bash
|
||||
# Test configuration
|
||||
sudo nginx -t
|
||||
|
||||
# If OK, reload Nginx
|
||||
sudo systemctl reload nginx
|
||||
|
||||
# Test the API
|
||||
curl https://connect5.beyondcloud.technology/api/db-status
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Check if Nginx is Running
|
||||
```bash
|
||||
sudo systemctl status nginx
|
||||
```
|
||||
|
||||
### Check Nginx Error Logs
|
||||
```bash
|
||||
sudo tail -f /var/log/nginx/error.log
|
||||
```
|
||||
|
||||
### Check if Node.js is Running
|
||||
```bash
|
||||
ps aux | grep "node server.js"
|
||||
```
|
||||
|
||||
### Test Local Node.js Server
|
||||
```bash
|
||||
curl http://localhost:3000/api/db-status
|
||||
```
|
||||
|
||||
### Restart Everything
|
||||
```bash
|
||||
# Restart Node.js
|
||||
pkill -f "node server.js"
|
||||
cd /home/github2/apps/app-connect5
|
||||
nohup node server.js > server.log 2>&1 &
|
||||
|
||||
# Reload Nginx
|
||||
sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## CloudSticks-Specific Notes
|
||||
|
||||
- CloudSticks uses **Nginx** (not Apache)
|
||||
- Config files are usually in `/etc/nginx/sites-available/`
|
||||
- CloudSticks auto-deploys from GitHub
|
||||
- Node.js server needs to run continuously in background
|
||||
|
||||
---
|
||||
|
||||
## Verify It's Working
|
||||
|
||||
1. **Test API endpoint**:
|
||||
```bash
|
||||
curl https://connect5.beyondcloud.technology/api/db-status
|
||||
```
|
||||
Should return JSON with `"connected": true`
|
||||
|
||||
2. **Visit in browser**:
|
||||
https://connect5.beyondcloud.technology/
|
||||
|
||||
Status bar should show:
|
||||
- SQL: Connected ✅
|
||||
- Latency: ~45ms
|
||||
- Write: Enabled ✅
|
||||
|
||||
3. **Test multiplayer**:
|
||||
- Click "Multiplayer"
|
||||
- Register a username
|
||||
- Should see "Welcome back, [username]!"
|
||||
@@ -1,251 +0,0 @@
|
||||
# Production Deployment Guide
|
||||
|
||||
## Quick Deployment
|
||||
|
||||
### Option 1: Automated Script (Recommended)
|
||||
|
||||
1. **Upload the deployment script** to your production server:
|
||||
```bash
|
||||
scp deploy-production.sh user@connect5.beyondcloud.technology:/tmp/
|
||||
```
|
||||
|
||||
2. **SSH into your server**:
|
||||
```bash
|
||||
ssh user@connect5.beyondcloud.technology
|
||||
```
|
||||
|
||||
3. **Update the script path** (if needed):
|
||||
```bash
|
||||
nano /tmp/deploy-production.sh
|
||||
# Change PROJECT_DIR to your actual path
|
||||
```
|
||||
|
||||
4. **Make it executable and run**:
|
||||
```bash
|
||||
chmod +x /tmp/deploy-production.sh
|
||||
sudo /tmp/deploy-production.sh
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Option 2: Manual Steps
|
||||
|
||||
If you prefer manual deployment:
|
||||
|
||||
1. **SSH into production server**:
|
||||
```bash
|
||||
ssh user@connect5.beyondcloud.technology
|
||||
```
|
||||
|
||||
2. **Navigate to project**:
|
||||
```bash
|
||||
cd /var/www/html/connect5.beyondcloud.technology # Your actual path
|
||||
```
|
||||
|
||||
3. **Pull latest code**:
|
||||
```bash
|
||||
git pull origin main
|
||||
npm install
|
||||
```
|
||||
|
||||
4. **Create db.config.js**:
|
||||
```bash
|
||||
nano db.config.js
|
||||
```
|
||||
|
||||
Paste:
|
||||
```javascript
|
||||
module.exports = {
|
||||
supabaseUrl: 'https://wxtirlphaphwbrgsjyop.supabase.co',
|
||||
supabaseAnonKey: 'sb_publishable_Onh4nNYCV99d2eGidQIpqA_9PBkY8zs',
|
||||
supabasePassword: 't1hWsackxbYzRIPD',
|
||||
postgresConnectionString: 'postgresql://postgres:t1hWsackxbYzRIPD@db.wxtirlphaphwbrgsjyop.supabase.co:5432/postgres'
|
||||
};
|
||||
```
|
||||
|
||||
Save with `Ctrl+X`, `Y`, `Enter`
|
||||
|
||||
5. **Restart server**:
|
||||
```bash
|
||||
pm2 restart connect5
|
||||
# or if not running:
|
||||
pm2 start server.js --name connect5
|
||||
pm2 save
|
||||
```
|
||||
|
||||
6. **Check status**:
|
||||
```bash
|
||||
pm2 status
|
||||
pm2 logs connect5
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Verification
|
||||
|
||||
### 1. Test API Endpoint
|
||||
```bash
|
||||
curl https://connect5.beyondcloud.technology/api/db-status
|
||||
```
|
||||
|
||||
Should return JSON like:
|
||||
```json
|
||||
{
|
||||
"connected": true,
|
||||
"latency": 45,
|
||||
"writeCapable": true,
|
||||
"database": "Supabase PostgreSQL"
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Test in Browser
|
||||
|
||||
1. Visit https://connect5.beyondcloud.technology/
|
||||
2. Check status bar at bottom:
|
||||
- **SQL**: Connected (green)
|
||||
- **Latency**: ~45ms
|
||||
- **Write**: Enabled (green)
|
||||
3. Click "Multiplayer"
|
||||
4. Enter a username
|
||||
5. Should see "Welcome back, [username]!"
|
||||
|
||||
### 3. Test Multiplayer
|
||||
|
||||
1. Open two browser windows
|
||||
2. Register different usernames in each
|
||||
3. Send a challenge from one to the other
|
||||
4. Accept and play a game
|
||||
5. Verify stats update after game ends
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### API Returns 404
|
||||
|
||||
**Check if Node.js is running**:
|
||||
```bash
|
||||
pm2 status
|
||||
```
|
||||
|
||||
**Check Apache proxy**:
|
||||
```bash
|
||||
sudo nano /etc/apache2/sites-available/connect5.conf
|
||||
```
|
||||
|
||||
Should have:
|
||||
```apache
|
||||
ProxyPass /api http://localhost:3000/api
|
||||
ProxyPassReverse /api http://localhost:3000/api
|
||||
ProxyPass /socket.io http://localhost:3000/socket.io
|
||||
ProxyPassReverse /socket.io http://localhost:3000/socket.io
|
||||
```
|
||||
|
||||
**Restart Apache**:
|
||||
```bash
|
||||
sudo systemctl restart apache2
|
||||
```
|
||||
|
||||
### WebSocket Connection Fails
|
||||
|
||||
**Enable Apache modules**:
|
||||
```bash
|
||||
sudo a2enmod proxy
|
||||
sudo a2enmod proxy_http
|
||||
sudo a2enmod proxy_wstunnel
|
||||
sudo a2enmod rewrite
|
||||
sudo systemctl restart apache2
|
||||
```
|
||||
|
||||
### Database Connection Fails
|
||||
|
||||
**Check Supabase credentials**:
|
||||
```bash
|
||||
cat db.config.js
|
||||
```
|
||||
|
||||
**Test connection**:
|
||||
```bash
|
||||
node -e "const {supabase} = require('./database'); supabase.from('players').select('id').limit(1).then(console.log)"
|
||||
```
|
||||
|
||||
### Server Won't Start
|
||||
|
||||
**Check logs**:
|
||||
```bash
|
||||
pm2 logs connect5 --lines 50
|
||||
```
|
||||
|
||||
**Check port availability**:
|
||||
```bash
|
||||
sudo netstat -tlnp | grep 3000
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Post-Deployment
|
||||
|
||||
### Monitor Server
|
||||
```bash
|
||||
pm2 monit
|
||||
```
|
||||
|
||||
### View Logs
|
||||
```bash
|
||||
pm2 logs connect5 --lines 100
|
||||
```
|
||||
|
||||
### Restart if Needed
|
||||
```bash
|
||||
pm2 restart connect5
|
||||
```
|
||||
|
||||
### Update Later
|
||||
```bash
|
||||
cd /var/www/html/connect5.beyondcloud.technology
|
||||
git pull origin main
|
||||
npm install
|
||||
pm2 restart connect5
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Apache Configuration Reference
|
||||
|
||||
If you need to set up Apache proxy from scratch:
|
||||
|
||||
```apache
|
||||
<VirtualHost *:443>
|
||||
ServerName connect5.beyondcloud.technology
|
||||
|
||||
DocumentRoot /var/www/html/connect5.beyondcloud.technology
|
||||
|
||||
<Directory /var/www/html/connect5.beyondcloud.technology>
|
||||
Options -Indexes +FollowSymLinks
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
# Proxy API and Socket.io to Node.js
|
||||
ProxyPreserveHost On
|
||||
ProxyPass /api http://localhost:3000/api
|
||||
ProxyPassReverse /api http://localhost:3000/api
|
||||
ProxyPass /socket.io http://localhost:3000/socket.io
|
||||
ProxyPassReverse /socket.io http://localhost:3000/socket.io
|
||||
|
||||
# WebSocket support
|
||||
RewriteEngine On
|
||||
RewriteCond %{HTTP:Upgrade} =websocket [NC]
|
||||
RewriteRule /(.*) ws://localhost:3000/$1 [P,L]
|
||||
|
||||
# SSL
|
||||
SSLEngine on
|
||||
SSLCertificateFile /etc/letsencrypt/live/connect5.beyondcloud.technology/fullchain.pem
|
||||
SSLCertificateKeyFile /etc/letsencrypt/live/connect5.beyondcloud.technology/privkey.pem
|
||||
</VirtualHost>
|
||||
```
|
||||
|
||||
Apply changes:
|
||||
```bash
|
||||
sudo systemctl restart apache2
|
||||
```
|
||||
86
README.md
86
README.md
@@ -10,7 +10,7 @@ A beautiful, feature-rich implementation of the classic Connect-5 (Gomoku) game
|
||||
|
||||
[](https://nodejs.org/)
|
||||
[](https://socket.io/)
|
||||
[](https://www.mysql.com/)
|
||||
[](https://supabase.com/)
|
||||
[](LICENSE)
|
||||
|
||||
[Play Now](https://connect5.beyondcloud.technology/) • [Features](#features) • [Installation](#installation) • [Usage](#usage) • [Multiplayer](#multiplayer) • [Tech Stack](#tech-stack)
|
||||
@@ -70,7 +70,7 @@ A beautiful, feature-rich implementation of the classic Connect-5 (Gomoku) game
|
||||
|
||||
### Prerequisites
|
||||
- **Node.js** 18+ ([Download](https://nodejs.org/))
|
||||
- **MySQL** 8.0+ ([Download](https://www.mysql.com/downloads/))
|
||||
- **Supabase Account** (Free tier available at [supabase.com](https://supabase.com/))
|
||||
- **Git** ([Download](https://git-scm.com/))
|
||||
|
||||
### Quick Start
|
||||
@@ -83,12 +83,13 @@ cd Connect-5
|
||||
# Install dependencies
|
||||
npm install
|
||||
|
||||
# Configure database (edit database.js with your credentials)
|
||||
# Update the following in database.js:
|
||||
# - host: 'your-mysql-host'
|
||||
# - user: 'your-database-user'
|
||||
# - password: 'your-password'
|
||||
# - database: 'your-database-name'
|
||||
# Configure database
|
||||
# 1. Create a Supabase project at https://supabase.com
|
||||
# 2. Copy db.config.example.js to db.config.js
|
||||
cp db.config.example.js db.config.js
|
||||
|
||||
# 3. Edit db.config.js with your Supabase credentials
|
||||
# 4. Run the SQL schema in Supabase SQL Editor (see SUPABASE_SETUP.md)
|
||||
|
||||
# Start the server
|
||||
npm start
|
||||
@@ -96,6 +97,8 @@ npm start
|
||||
|
||||
The server will start on **http://localhost:3000**
|
||||
|
||||
For detailed setup instructions, see [SUPABASE_SETUP.md](SUPABASE_SETUP.md)
|
||||
|
||||
---
|
||||
|
||||
## 🎮 Usage
|
||||
@@ -137,8 +140,8 @@ The server will start on **http://localhost:3000**
|
||||
│
|
||||
▼
|
||||
┌──────────────┐
|
||||
│ MySQL │
|
||||
│ Database │
|
||||
│ Supabase │
|
||||
│ PostgreSQL │
|
||||
└──────────────┘
|
||||
```
|
||||
|
||||
@@ -186,18 +189,19 @@ The server will start on **http://localhost:3000**
|
||||
- **Node.js**: JavaScript runtime
|
||||
- **Express.js**: Web application framework
|
||||
- **Socket.io**: WebSocket library for real-time bidirectional communication
|
||||
- **MySQL2**: MySQL database driver with promises
|
||||
- **Supabase Client**: PostgreSQL database client with real-time capabilities
|
||||
|
||||
### Database
|
||||
- **MySQL**: Relational database for persistent storage
|
||||
- **Connection Pooling**: Optimized database connections
|
||||
- **Supabase**: Managed PostgreSQL database with real-time subscriptions
|
||||
- **Row Level Security**: Built-in security policies
|
||||
- **Auto-generated APIs**: RESTful and real-time APIs
|
||||
|
||||
### Dependencies
|
||||
```json
|
||||
{
|
||||
"express": "^4.18.2",
|
||||
"socket.io": "^4.6.1",
|
||||
"mysql2": "^3.2.0",
|
||||
"@supabase/supabase-js": "^2.39.0",
|
||||
"bad-words": "^3.0.4",
|
||||
"cors": "^2.8.5",
|
||||
"nodemon": "^2.0.22"
|
||||
@@ -229,20 +233,25 @@ Connect-5/
|
||||
|
||||
### Database Configuration
|
||||
|
||||
Edit `database.js`:
|
||||
Create `db.config.js` from the example:
|
||||
|
||||
```bash
|
||||
cp db.config.example.js db.config.js
|
||||
```
|
||||
|
||||
Edit `db.config.js`:
|
||||
|
||||
```javascript
|
||||
const dbConfig = {
|
||||
host: 'your-mysql-host', // MySQL server address
|
||||
user: 'your-database-user', // Database username
|
||||
password: 'your-password', // Database password
|
||||
database: 'your-database-name',// Database name
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0
|
||||
module.exports = {
|
||||
supabaseUrl: 'https://your-project.supabase.co',
|
||||
supabaseAnonKey: 'your-anon-key-here',
|
||||
supabasePassword: 'your-database-password',
|
||||
postgresConnectionString: 'postgresql://postgres:password@...'
|
||||
};
|
||||
```
|
||||
|
||||
See [SUPABASE_SETUP.md](SUPABASE_SETUP.md) for detailed setup instructions.
|
||||
|
||||
### Server Configuration
|
||||
|
||||
Edit `server.js` to change the port:
|
||||
@@ -253,6 +262,27 @@ const PORT = process.env.PORT || 3000;
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Production Deployment
|
||||
|
||||
For production deployment, use the automated deployment script:
|
||||
|
||||
```bash
|
||||
sudo bash deploy.sh
|
||||
```
|
||||
|
||||
The script will:
|
||||
- ✅ Prompt for project directory
|
||||
- ✅ Request Supabase credentials
|
||||
- ✅ Configure database connection
|
||||
- ✅ Install dependencies
|
||||
- ✅ Detect and configure web server (Nginx/Apache)
|
||||
- ✅ Start Node.js server
|
||||
- ✅ Test endpoints
|
||||
|
||||
See [DEPLOYMENT.md](DEPLOYMENT.md) for detailed deployment instructions.
|
||||
|
||||
---
|
||||
|
||||
## 🎯 Game Rules
|
||||
|
||||
### Objective
|
||||
@@ -298,8 +328,8 @@ npm start
|
||||
## 🐛 Troubleshooting
|
||||
|
||||
### Connection Refused Error
|
||||
**Problem**: Cannot connect to MySQL database
|
||||
**Solution**: Ensure MySQL is running and credentials in `database.js` are correct
|
||||
**Problem**: Cannot connect to Supabase database
|
||||
**Solution**: Verify credentials in `db.config.js` and check Supabase dashboard
|
||||
|
||||
### Port Already in Use
|
||||
**Problem**: Port 3000 is already occupied
|
||||
@@ -313,6 +343,12 @@ npm start
|
||||
**Problem**: Username registration fails
|
||||
**Solution**: Try a different username or check the database for duplicates
|
||||
|
||||
### Database Disconnected
|
||||
**Problem**: Status bar shows "Disconnected"
|
||||
**Solution**: Check `db.config.js` credentials and Supabase project status
|
||||
|
||||
For more troubleshooting, see [DEPLOYMENT.md](DEPLOYMENT.md)
|
||||
|
||||
---
|
||||
|
||||
## 🤝 Contributing
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
# Apache Configuration for Connect-5
|
||||
# Add this to your Apache virtual host configuration
|
||||
|
||||
# Enable required modules (run these commands first):
|
||||
# sudo a2enmod proxy
|
||||
# sudo a2enmod proxy_http
|
||||
# sudo a2enmod proxy_wstunnel
|
||||
# sudo a2enmod rewrite
|
||||
# sudo systemctl restart apache2
|
||||
|
||||
<VirtualHost *:443>
|
||||
ServerName connect5.beyondcloud.technology
|
||||
|
||||
# Your existing SSL and document root settings
|
||||
DocumentRoot /home/github2/apps/app-connect5
|
||||
|
||||
# Proxy API requests to Node.js
|
||||
ProxyPreserveHost On
|
||||
ProxyPass /api http://localhost:3000/api
|
||||
ProxyPassReverse /api http://localhost:3000/api
|
||||
|
||||
# Proxy Socket.io WebSocket requests
|
||||
ProxyPass /socket.io http://localhost:3000/socket.io
|
||||
ProxyPassReverse /socket.io http://localhost:3000/socket.io
|
||||
|
||||
# WebSocket upgrade support
|
||||
RewriteEngine On
|
||||
RewriteCond %{HTTP:Upgrade} =websocket [NC]
|
||||
RewriteRule /(.*) ws://localhost:3000/$1 [P,L]
|
||||
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
|
||||
RewriteRule /(.*) http://localhost:3000/$1 [P,L]
|
||||
|
||||
# Your existing SSL configuration
|
||||
SSLEngine on
|
||||
# SSLCertificateFile /path/to/cert
|
||||
# SSLCertificateKeyFile /path/to/key
|
||||
</VirtualHost>
|
||||
|
||||
# If you also need HTTP (port 80) redirect:
|
||||
<VirtualHost *:80>
|
||||
ServerName connect5.beyondcloud.technology
|
||||
Redirect permanent / https://connect5.beyondcloud.technology/
|
||||
</VirtualHost>
|
||||
@@ -1,35 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Check CloudSticks Nginx configuration structure
|
||||
|
||||
echo "🔍 Checking CloudSticks Nginx Configuration"
|
||||
echo "============================================"
|
||||
echo ""
|
||||
|
||||
echo "1. Main nginx.conf location:"
|
||||
ls -la /etc/nginx-cs/nginx.conf 2>/dev/null || echo "Not found"
|
||||
echo ""
|
||||
|
||||
echo "2. Checking what nginx.conf includes:"
|
||||
grep -n "include" /etc/nginx-cs/nginx.conf 2>/dev/null || echo "No includes found"
|
||||
echo ""
|
||||
|
||||
echo "3. Directory structure:"
|
||||
ls -la /etc/nginx-cs/ 2>/dev/null
|
||||
echo ""
|
||||
|
||||
echo "4. Checking for vhosts directories:"
|
||||
ls -la /etc/nginx-cs/vhosts.d/ 2>/dev/null || echo "No vhosts.d"
|
||||
ls -la /etc/nginx-cs/sites-available/ 2>/dev/null || echo "No sites-available"
|
||||
ls -la /etc/nginx-cs/sites-enabled/ 2>/dev/null || echo "No sites-enabled"
|
||||
echo ""
|
||||
|
||||
echo "5. Our proxy config:"
|
||||
ls -la /etc/nginx-cs/conf.d/connect5-proxy.conf 2>/dev/null || echo "Proxy config not found"
|
||||
echo ""
|
||||
|
||||
echo "6. Nginx process:"
|
||||
ps aux | grep nginx | grep -v grep
|
||||
echo ""
|
||||
|
||||
echo "7. Listening ports:"
|
||||
netstat -tlnp 2>/dev/null | grep :443 || ss -tlnp | grep :443
|
||||
@@ -1,123 +0,0 @@
|
||||
#!/bin/bash
|
||||
# CloudSticks Deployment Script for Connect-5
|
||||
# This version works without PM2 - uses systemd or direct node
|
||||
|
||||
set -e # Exit on error
|
||||
|
||||
echo "🚀 Connect-5 CloudSticks Deployment"
|
||||
echo "===================================="
|
||||
echo ""
|
||||
|
||||
# Configuration
|
||||
PROJECT_DIR="/home/github2/apps/app-connect5"
|
||||
NODE_PORT=3000
|
||||
|
||||
# Colors for output
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Step 1: Navigate to project directory
|
||||
echo "📁 Navigating to project directory..."
|
||||
cd "$PROJECT_DIR" || { echo -e "${RED}❌ Project directory not found!${NC}"; exit 1; }
|
||||
echo -e "${GREEN}✅ In directory: $(pwd)${NC}"
|
||||
echo ""
|
||||
|
||||
# Step 2: Install dependencies
|
||||
echo "📦 Installing dependencies..."
|
||||
npm install || { echo -e "${RED}❌ npm install failed!${NC}"; exit 1; }
|
||||
echo -e "${GREEN}✅ Dependencies installed${NC}"
|
||||
echo ""
|
||||
|
||||
# Step 3: Check if db.config.js exists
|
||||
echo "🔍 Checking for db.config.js..."
|
||||
if [ ! -f "db.config.js" ]; then
|
||||
echo -e "${YELLOW}⚠️ db.config.js not found!${NC}"
|
||||
echo "Creating db.config.js from template..."
|
||||
|
||||
cat > db.config.js << 'EOF'
|
||||
// Database Configuration File
|
||||
// IMPORTANT: This file contains sensitive credentials
|
||||
// DO NOT commit this file to git - it's in .gitignore
|
||||
|
||||
// Supabase Configuration
|
||||
module.exports = {
|
||||
supabaseUrl: 'https://wxtirlphaphwbrgsjyop.supabase.co',
|
||||
supabaseAnonKey: 'sb_publishable_Onh4nNYCV99d2eGidQIpqA_9PBkY8zs',
|
||||
supabasePassword: 't1hWsackxbYzRIPD',
|
||||
|
||||
// Optional: Direct PostgreSQL connection
|
||||
postgresConnectionString: 'postgresql://postgres:t1hWsackxbYzRIPD@db.wxtirlphaphwbrgsjyop.supabase.co:5432/postgres'
|
||||
};
|
||||
EOF
|
||||
|
||||
echo -e "${GREEN}✅ db.config.js created${NC}"
|
||||
else
|
||||
echo -e "${GREEN}✅ db.config.js already exists${NC}"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Step 4: Check how to restart the server
|
||||
echo "🔄 Checking server management..."
|
||||
|
||||
# Check if systemd service exists
|
||||
if systemctl list-units --type=service --all | grep -q "connect5.service"; then
|
||||
echo "Found systemd service, restarting..."
|
||||
sudo systemctl restart connect5
|
||||
echo -e "${GREEN}✅ Server restarted via systemd${NC}"
|
||||
|
||||
elif command -v pm2 &> /dev/null; then
|
||||
echo "Found PM2, restarting..."
|
||||
pm2 restart connect5 || pm2 start server.js --name connect5
|
||||
pm2 save
|
||||
echo -e "${GREEN}✅ Server restarted via PM2${NC}"
|
||||
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ No process manager found${NC}"
|
||||
echo "Please restart your Node.js server manually:"
|
||||
echo " Option 1: If using systemd: sudo systemctl restart connect5"
|
||||
echo " Option 2: If using PM2: pm2 restart connect5"
|
||||
echo " Option 3: Kill existing node process and start new one"
|
||||
echo ""
|
||||
echo "To start the server manually:"
|
||||
echo " cd $PROJECT_DIR"
|
||||
echo " node server.js &"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Step 5: Test API endpoint (if server is running)
|
||||
echo "🧪 Testing API endpoint..."
|
||||
sleep 3 # Give server time to start
|
||||
|
||||
API_RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:$NODE_PORT/api/db-status 2>/dev/null || echo "000")
|
||||
|
||||
if [ "$API_RESPONSE" = "200" ]; then
|
||||
echo -e "${GREEN}✅ API endpoint responding (HTTP $API_RESPONSE)${NC}"
|
||||
|
||||
# Get actual status
|
||||
echo ""
|
||||
echo "📊 Database Status:"
|
||||
curl -s http://localhost:$NODE_PORT/api/db-status | python3 -m json.tool 2>/dev/null || echo "Could not parse JSON"
|
||||
|
||||
elif [ "$API_RESPONSE" = "000" ]; then
|
||||
echo -e "${YELLOW}⚠️ Could not connect to server${NC}"
|
||||
echo "The server might not be running yet."
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ API endpoint returned HTTP $API_RESPONSE${NC}"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Final instructions
|
||||
echo "===================================="
|
||||
echo -e "${GREEN}🎉 Deployment Steps Complete!${NC}"
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo "1. Ensure Node.js server is running"
|
||||
echo "2. Visit https://connect5.beyondcloud.technology/"
|
||||
echo "3. Check the status bar shows 'Connected'"
|
||||
echo ""
|
||||
echo "If server is not running, start it with:"
|
||||
echo " cd $PROJECT_DIR"
|
||||
echo " node server.js > server.log 2>&1 &"
|
||||
echo "===================================="
|
||||
@@ -1,112 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Production Deployment Script for Connect-5 Supabase Migration
|
||||
# Run this on your production server
|
||||
|
||||
set -e # Exit on error
|
||||
|
||||
echo "🚀 Connect-5 Production Deployment"
|
||||
echo "===================================="
|
||||
echo ""
|
||||
|
||||
# Configuration
|
||||
PROJECT_DIR="/home/github2/apps/app-connect5" # Production server path
|
||||
NODE_PORT=3000
|
||||
PM2_APP_NAME="connect5"
|
||||
|
||||
# Colors for output
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Step 1: Navigate to project directory
|
||||
echo "📁 Navigating to project directory..."
|
||||
cd "$PROJECT_DIR" || { echo -e "${RED}❌ Project directory not found!${NC}"; exit 1; }
|
||||
echo -e "${GREEN}✅ In directory: $(pwd)${NC}"
|
||||
echo ""
|
||||
|
||||
# Step 2: Install dependencies
|
||||
echo "📦 Installing dependencies..."
|
||||
npm install || { echo -e "${RED}❌ npm install failed!${NC}"; exit 1; }
|
||||
echo -e "${GREEN}✅ Dependencies installed${NC}"
|
||||
echo ""
|
||||
|
||||
# Step 3: Check if db.config.js exists
|
||||
echo "🔍 Checking for db.config.js..."
|
||||
if [ ! -f "db.config.js" ]; then
|
||||
echo -e "${YELLOW}⚠️ db.config.js not found!${NC}"
|
||||
echo "Creating db.config.js from template..."
|
||||
|
||||
cat > db.config.js << 'EOF'
|
||||
// Database Configuration File
|
||||
// IMPORTANT: This file contains sensitive credentials
|
||||
// DO NOT commit this file to git - it's in .gitignore
|
||||
|
||||
// Supabase Configuration
|
||||
module.exports = {
|
||||
supabaseUrl: 'https://wxtirlphaphwbrgsjyop.supabase.co',
|
||||
supabaseAnonKey: 'sb_publishable_Onh4nNYCV99d2eGidQIpqA_9PBkY8zs',
|
||||
supabasePassword: 't1hWsackxbYzRIPD',
|
||||
|
||||
// Optional: Direct PostgreSQL connection
|
||||
postgresConnectionString: 'postgresql://postgres:t1hWsackxbYzRIPD@db.wxtirlphaphwbrgsjyop.supabase.co:5432/postgres'
|
||||
};
|
||||
EOF
|
||||
|
||||
echo -e "${GREEN}✅ db.config.js created${NC}"
|
||||
else
|
||||
echo -e "${GREEN}✅ db.config.js already exists${NC}"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Step 4: Restart Node.js server with PM2
|
||||
echo "🔄 Restarting Node.js server..."
|
||||
if pm2 list | grep -q "$PM2_APP_NAME"; then
|
||||
echo "Restarting existing PM2 process..."
|
||||
pm2 restart "$PM2_APP_NAME" || { echo -e "${RED}❌ PM2 restart failed!${NC}"; exit 1; }
|
||||
else
|
||||
echo "Starting new PM2 process..."
|
||||
pm2 start server.js --name "$PM2_APP_NAME" || { echo -e "${RED}❌ PM2 start failed!${NC}"; exit 1; }
|
||||
fi
|
||||
|
||||
pm2 save
|
||||
echo -e "${GREEN}✅ Server restarted${NC}"
|
||||
echo ""
|
||||
|
||||
# Step 5: Show server status
|
||||
echo "📊 Server Status:"
|
||||
pm2 status
|
||||
echo ""
|
||||
|
||||
# Step 6: Test API endpoint
|
||||
echo "🧪 Testing API endpoint..."
|
||||
sleep 2 # Give server time to start
|
||||
API_RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:$NODE_PORT/api/db-status)
|
||||
|
||||
if [ "$API_RESPONSE" = "200" ]; then
|
||||
echo -e "${GREEN}✅ API endpoint responding (HTTP $API_RESPONSE)${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ API endpoint returned HTTP $API_RESPONSE${NC}"
|
||||
echo "Check logs with: pm2 logs $PM2_APP_NAME"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Step 7: Show recent logs
|
||||
echo "📋 Recent server logs:"
|
||||
pm2 logs "$PM2_APP_NAME" --lines 20 --nostream
|
||||
echo ""
|
||||
|
||||
# Final instructions
|
||||
echo "===================================="
|
||||
echo -e "${GREEN}🎉 Deployment Complete!${NC}"
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo "1. Visit https://connect5.beyondcloud.technology/"
|
||||
echo "2. Check the status bar shows 'Connected'"
|
||||
echo "3. Test multiplayer functionality"
|
||||
echo ""
|
||||
echo "Useful commands:"
|
||||
echo " pm2 logs $PM2_APP_NAME - View server logs"
|
||||
echo " pm2 restart $PM2_APP_NAME - Restart server"
|
||||
echo " pm2 stop $PM2_APP_NAME - Stop server"
|
||||
echo "===================================="
|
||||
260
deploy.sh
Normal file
260
deploy.sh
Normal file
@@ -0,0 +1,260 @@
|
||||
#!/bin/bash
|
||||
# Connect-5 Production Deployment Script
|
||||
# Supports CloudSticks and standard servers with Nginx or Apache
|
||||
|
||||
set -e
|
||||
|
||||
echo "╔════════════════════════════════════════════════════════════╗"
|
||||
echo "║ Connect-5 Production Deployment Script ║"
|
||||
echo "║ Supabase + Node.js + Nginx/Apache ║"
|
||||
echo "╚════════════════════════════════════════════════════════════╝"
|
||||
echo ""
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
# Check if running as root
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo -e "${RED}❌ This script must be run as root (use sudo)${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get project directory
|
||||
echo -e "${BLUE}📁 Project Directory${NC}"
|
||||
echo "Current directory: $(pwd)"
|
||||
echo ""
|
||||
read -p "Enter project path (or press Enter to use current directory): " PROJECT_DIR
|
||||
|
||||
if [ -z "$PROJECT_DIR" ]; then
|
||||
PROJECT_DIR=$(pwd)
|
||||
fi
|
||||
|
||||
# Validate directory
|
||||
if [ ! -d "$PROJECT_DIR" ]; then
|
||||
echo -e "${RED}❌ Directory does not exist: $PROJECT_DIR${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$PROJECT_DIR/package.json" ]; then
|
||||
echo -e "${RED}❌ Not a valid Connect-5 project (package.json not found)${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$PROJECT_DIR"
|
||||
echo -e "${GREEN}✅ Using project directory: $PROJECT_DIR${NC}"
|
||||
echo ""
|
||||
|
||||
# Get Supabase credentials
|
||||
echo -e "${BLUE}🔐 Supabase Configuration${NC}"
|
||||
echo ""
|
||||
read -p "Supabase URL: " SUPABASE_URL
|
||||
read -p "Supabase Anon Key: " SUPABASE_KEY
|
||||
read -s -p "Supabase Password: " SUPABASE_PASSWORD
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
if [ -z "$SUPABASE_URL" ] || [ -z "$SUPABASE_KEY" ]; then
|
||||
echo -e "${RED}❌ Supabase credentials are required${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create db.config.js
|
||||
echo -e "${BLUE}📝 Creating db.config.js...${NC}"
|
||||
cat > "$PROJECT_DIR/db.config.js" << EOF
|
||||
module.exports = {
|
||||
// Supabase Configuration
|
||||
supabaseUrl: '$SUPABASE_URL',
|
||||
supabaseAnonKey: '$SUPABASE_KEY',
|
||||
supabasePassword: '$SUPABASE_PASSWORD',
|
||||
|
||||
// PostgreSQL Connection String (optional, for direct connections)
|
||||
postgresConnectionString: 'postgresql://postgres:$SUPABASE_PASSWORD@db.${SUPABASE_URL#https://}.supabase.co:5432/postgres'
|
||||
};
|
||||
EOF
|
||||
echo -e "${GREEN}✅ db.config.js created${NC}"
|
||||
echo ""
|
||||
|
||||
# Install dependencies
|
||||
echo -e "${BLUE}📦 Installing dependencies...${NC}"
|
||||
npm install
|
||||
echo -e "${GREEN}✅ Dependencies installed${NC}"
|
||||
echo ""
|
||||
|
||||
# Detect web server
|
||||
echo -e "${BLUE}🌐 Detecting web server...${NC}"
|
||||
WEB_SERVER=""
|
||||
if systemctl list-units | grep -q "nginx-cs"; then
|
||||
WEB_SERVER="nginx-cs"
|
||||
echo -e "${GREEN}✅ Detected: CloudSticks Nginx${NC}"
|
||||
elif systemctl list-units | grep -q "nginx.service"; then
|
||||
WEB_SERVER="nginx"
|
||||
echo -e "${GREEN}✅ Detected: Standard Nginx${NC}"
|
||||
elif systemctl list-units | grep -q "apache2"; then
|
||||
WEB_SERVER="apache2"
|
||||
echo -e "${GREEN}✅ Detected: Apache${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Could not detect web server${NC}"
|
||||
echo "Please select:"
|
||||
echo "1) CloudSticks Nginx (nginx-cs)"
|
||||
echo "2) Standard Nginx"
|
||||
echo "3) Apache"
|
||||
read -p "Selection: " SERVER_CHOICE
|
||||
case $SERVER_CHOICE in
|
||||
1) WEB_SERVER="nginx-cs" ;;
|
||||
2) WEB_SERVER="nginx" ;;
|
||||
3) WEB_SERVER="apache2" ;;
|
||||
*) echo -e "${RED}❌ Invalid selection${NC}"; exit 1 ;;
|
||||
esac
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Configure web server
|
||||
case $WEB_SERVER in
|
||||
"nginx-cs")
|
||||
echo -e "${BLUE}⚙️ Configuring CloudSticks Nginx...${NC}"
|
||||
|
||||
# Find existing vhost config
|
||||
DOMAIN=$(basename "$PROJECT_DIR" | sed 's/app-//')
|
||||
VHOST_FILE="/etc/nginx-cs/vhosts.d/app-${DOMAIN}.conf"
|
||||
|
||||
if [ ! -f "$VHOST_FILE" ]; then
|
||||
echo -e "${YELLOW}⚠️ Vhost file not found: $VHOST_FILE${NC}"
|
||||
echo "Available vhost files:"
|
||||
ls -1 /etc/nginx-cs/vhosts.d/ | grep ".conf$"
|
||||
read -p "Enter vhost filename: " VHOST_NAME
|
||||
VHOST_FILE="/etc/nginx-cs/vhosts.d/$VHOST_NAME"
|
||||
fi
|
||||
|
||||
if [ ! -f "$VHOST_FILE" ]; then
|
||||
echo -e "${RED}❌ Vhost file not found${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Backup
|
||||
cp "$VHOST_FILE" "${VHOST_FILE}.backup.$(date +%Y%m%d_%H%M%S)"
|
||||
|
||||
# Check if proxy rules already exist
|
||||
if grep -q "proxy_pass.*3000" "$VHOST_FILE"; then
|
||||
echo -e "${YELLOW}⚠️ Proxy rules already exist${NC}"
|
||||
else
|
||||
# Add proxy rules before closing brace
|
||||
sed -i '/^}$/i\
|
||||
\
|
||||
# Connect-5 API Proxy\
|
||||
location /api {\
|
||||
proxy_pass http://localhost:3000;\
|
||||
proxy_http_version 1.1;\
|
||||
proxy_set_header Upgrade $http_upgrade;\
|
||||
proxy_set_header Connection '"'"'upgrade'"'"';\
|
||||
proxy_set_header Host $host;\
|
||||
proxy_cache_bypass $http_upgrade;\
|
||||
proxy_set_header X-Real-IP $remote_addr;\
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\
|
||||
proxy_set_header X-Forwarded-Proto $scheme;\
|
||||
}\
|
||||
\
|
||||
# Connect-5 Socket.io Proxy\
|
||||
location /socket.io {\
|
||||
proxy_pass http://localhost:3000;\
|
||||
proxy_http_version 1.1;\
|
||||
proxy_set_header Upgrade $http_upgrade;\
|
||||
proxy_set_header Connection "upgrade";\
|
||||
proxy_set_header Host $host;\
|
||||
proxy_cache_bypass $http_upgrade;\
|
||||
proxy_set_header X-Real-IP $remote_addr;\
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\
|
||||
proxy_set_header X-Forwarded-Proto $scheme;\
|
||||
}' "$VHOST_FILE"
|
||||
|
||||
echo -e "${GREEN}✅ Proxy rules added to $VHOST_FILE${NC}"
|
||||
fi
|
||||
|
||||
systemctl restart nginx-cs
|
||||
echo -e "${GREEN}✅ Nginx-CS restarted${NC}"
|
||||
;;
|
||||
|
||||
"nginx")
|
||||
echo -e "${BLUE}⚙️ Configuring Standard Nginx...${NC}"
|
||||
echo "Please manually add proxy configuration to your Nginx vhost"
|
||||
echo "See DEPLOYMENT.md for instructions"
|
||||
;;
|
||||
|
||||
"apache2")
|
||||
echo -e "${BLUE}⚙️ Configuring Apache...${NC}"
|
||||
echo "Enabling required modules..."
|
||||
a2enmod proxy proxy_http proxy_wstunnel rewrite 2>/dev/null || true
|
||||
echo "Please manually add proxy configuration to your Apache vhost"
|
||||
echo "See DEPLOYMENT.md for instructions"
|
||||
systemctl restart apache2
|
||||
;;
|
||||
esac
|
||||
echo ""
|
||||
|
||||
# Start Node.js server
|
||||
echo -e "${BLUE}🚀 Starting Node.js server...${NC}"
|
||||
if pgrep -f "node server.js" > /dev/null; then
|
||||
echo -e "${YELLOW}⚠️ Server already running, restarting...${NC}"
|
||||
pkill -f "node server.js"
|
||||
sleep 2
|
||||
fi
|
||||
|
||||
cd "$PROJECT_DIR"
|
||||
nohup node server.js > server.log 2>&1 &
|
||||
sleep 3
|
||||
|
||||
if pgrep -f "node server.js" > /dev/null; then
|
||||
PID=$(pgrep -f "node server.js")
|
||||
echo -e "${GREEN}✅ Node.js server started (PID: $PID)${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Failed to start Node.js server${NC}"
|
||||
echo "Check server.log for errors"
|
||||
exit 1
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Test endpoints
|
||||
echo -e "${BLUE}🧪 Testing endpoints...${NC}"
|
||||
sleep 2
|
||||
|
||||
LOCAL=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/api/db-status 2>/dev/null || echo "000")
|
||||
echo "Local (localhost:3000): HTTP $LOCAL"
|
||||
|
||||
if [ "$LOCAL" = "200" ]; then
|
||||
echo -e "${GREEN}✅ Local endpoint working${NC}"
|
||||
echo ""
|
||||
echo "Database Status:"
|
||||
curl -s http://localhost:3000/api/db-status | python3 -m json.tool 2>/dev/null || curl -s http://localhost:3000/api/db-status
|
||||
else
|
||||
echo -e "${RED}❌ Local endpoint failed${NC}"
|
||||
echo "Check server.log for errors"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Final summary
|
||||
echo "╔════════════════════════════════════════════════════════════╗"
|
||||
echo "║ Deployment Complete! ║"
|
||||
echo "╚════════════════════════════════════════════════════════════╝"
|
||||
echo ""
|
||||
echo -e "${GREEN}✅ Project Directory:${NC} $PROJECT_DIR"
|
||||
echo -e "${GREEN}✅ Database:${NC} Supabase PostgreSQL"
|
||||
echo -e "${GREEN}✅ Web Server:${NC} $WEB_SERVER"
|
||||
echo -e "${GREEN}✅ Node.js:${NC} Running on port 3000"
|
||||
echo ""
|
||||
echo "📋 Next Steps:"
|
||||
echo "1. Test your production URL"
|
||||
echo "2. Check status bar shows 'Connected'"
|
||||
echo "3. Test multiplayer functionality"
|
||||
echo ""
|
||||
echo "📝 Logs:"
|
||||
echo " Node.js: tail -f $PROJECT_DIR/server.log"
|
||||
echo " Web Server: journalctl -u $WEB_SERVER -f"
|
||||
echo ""
|
||||
echo "🔧 Troubleshooting:"
|
||||
echo " - If API returns 404, check web server proxy configuration"
|
||||
echo " - If database disconnected, verify Supabase credentials"
|
||||
echo " - See DEPLOYMENT.md for detailed instructions"
|
||||
echo ""
|
||||
@@ -1,25 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Quick script to find and list Apache config files
|
||||
|
||||
echo "🔍 Finding Apache configuration files..."
|
||||
echo ""
|
||||
|
||||
echo "SSL-enabled sites:"
|
||||
ls -lh /etc/apache2/sites-enabled/ 2>/dev/null | grep -v "^total" | grep -v "^d"
|
||||
|
||||
echo ""
|
||||
echo "Available sites:"
|
||||
ls -lh /etc/apache2/sites-available/ 2>/dev/null | grep -v "^total" | grep -v "^d"
|
||||
|
||||
echo ""
|
||||
echo "Checking for connect5 or beyondcloud in configs:"
|
||||
grep -l "connect5\|beyondcloud" /etc/apache2/sites-available/* 2>/dev/null
|
||||
grep -l "connect5\|beyondcloud" /etc/apache2/sites-enabled/* 2>/dev/null
|
||||
|
||||
echo ""
|
||||
echo "Checking main Apache config:"
|
||||
grep -n "Include" /etc/apache2/apache2.conf | grep sites
|
||||
|
||||
echo ""
|
||||
echo "Current VirtualHosts:"
|
||||
apache2ctl -S 2>/dev/null | grep -A 2 "443\|beyondcloud\|connect5"
|
||||
@@ -1,105 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Move proxy config to correct CloudSticks directory
|
||||
|
||||
echo "🔧 Moving proxy config to correct location"
|
||||
echo "==========================================="
|
||||
echo ""
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m'
|
||||
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo -e "${RED}❌ Run with sudo${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Step 1: Moving config to vhosts.d..."
|
||||
if [ -f "/etc/nginx-cs/conf.d/connect5-proxy.conf" ]; then
|
||||
mv /etc/nginx-cs/conf.d/connect5-proxy.conf /etc/nginx-cs/vhosts.d/connect5-proxy.conf
|
||||
echo -e "${GREEN}✅ Moved to /etc/nginx-cs/vhosts.d/connect5-proxy.conf${NC}"
|
||||
else
|
||||
echo "Creating new config in vhosts.d..."
|
||||
cat > /etc/nginx-cs/vhosts.d/connect5-proxy.conf << 'EOF'
|
||||
# Connect-5 Proxy Configuration
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name connect5.beyondcloud.technology;
|
||||
|
||||
root /home/github2/apps/app-connect5;
|
||||
index index.html;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location /api {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location /socket.io {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
echo -e "${GREEN}✅ Created in vhosts.d${NC}"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "Step 2: Restarting Nginx..."
|
||||
systemctl restart nginx
|
||||
echo -e "${GREEN}✅ Nginx restarted${NC}"
|
||||
echo ""
|
||||
|
||||
echo "Step 3: Checking Node.js..."
|
||||
if ! pgrep -f "node server.js" > /dev/null; then
|
||||
echo "Starting Node.js..."
|
||||
cd /home/github2/apps/app-connect5
|
||||
nohup node server.js > server.log 2>&1 &
|
||||
sleep 2
|
||||
fi
|
||||
echo -e "${GREEN}✅ Node.js running${NC}"
|
||||
echo ""
|
||||
|
||||
echo "Step 4: Testing..."
|
||||
sleep 2
|
||||
|
||||
LOCAL=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/api/db-status 2>/dev/null || echo "000")
|
||||
PROD=$(curl -s -o /dev/null -w "%{http_code}" https://connect5.beyondcloud.technology/api/db-status 2>/dev/null || echo "000")
|
||||
|
||||
echo "Local: HTTP $LOCAL"
|
||||
echo "Production: HTTP $PROD"
|
||||
echo ""
|
||||
|
||||
if [ "$PROD" = "200" ]; then
|
||||
echo -e "${GREEN}✅✅✅ SUCCESS! ✅✅✅${NC}"
|
||||
echo ""
|
||||
echo "Database Status:"
|
||||
curl -s https://connect5.beyondcloud.technology/api/db-status | python3 -m json.tool 2>/dev/null || curl -s https://connect5.beyondcloud.technology/api/db-status
|
||||
echo ""
|
||||
echo "==========================================="
|
||||
echo -e "${GREEN}🎉 Production is LIVE!${NC}"
|
||||
echo "Visit: https://connect5.beyondcloud.technology/"
|
||||
echo "==========================================="
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Still getting HTTP $PROD${NC}"
|
||||
echo "Check logs:"
|
||||
echo " tail -f /home/github2/apps/app-connect5/server.log"
|
||||
fi
|
||||
131
node_modules/.package-lock.json
generated
vendored
131
node_modules/.package-lock.json
generated
vendored
@@ -10,6 +10,107 @@
|
||||
"integrity": "sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@supabase/auth-js": {
|
||||
"version": "2.89.0",
|
||||
"resolved": "https://registry.npmjs.org/@supabase/auth-js/-/auth-js-2.89.0.tgz",
|
||||
"integrity": "sha512-wiWZdz8WMad8LQdJMWYDZ2SJtZP5MwMqzQq3ehtW2ngiI3UTgbKiFrvMUUS3KADiVlk4LiGfODB2mrYx7w2f8w==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tslib": "2.8.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@supabase/functions-js": {
|
||||
"version": "2.89.0",
|
||||
"resolved": "https://registry.npmjs.org/@supabase/functions-js/-/functions-js-2.89.0.tgz",
|
||||
"integrity": "sha512-XEueaC5gMe5NufNYfBh9kPwJlP5M2f+Ogr8rvhmRDAZNHgY6mI35RCkYDijd92pMcNM7g8pUUJov93UGUnqfyw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tslib": "2.8.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@supabase/postgrest-js": {
|
||||
"version": "2.89.0",
|
||||
"resolved": "https://registry.npmjs.org/@supabase/postgrest-js/-/postgrest-js-2.89.0.tgz",
|
||||
"integrity": "sha512-/b0fKrxV9i7RNOEXMno/I1862RsYhuUo+Q6m6z3ar1f4ulTMXnDfv0y4YYxK2POcgrOXQOgKYQx1eArybyNvtg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tslib": "2.8.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@supabase/realtime-js": {
|
||||
"version": "2.89.0",
|
||||
"resolved": "https://registry.npmjs.org/@supabase/realtime-js/-/realtime-js-2.89.0.tgz",
|
||||
"integrity": "sha512-aMOvfDb2a52u6PX6jrrjvACHXGV3zsOlWRzZsTIOAJa0hOVvRp01AwC1+nLTGUzxzezejrYeCX+KnnM1xHdl+w==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/phoenix": "^1.6.6",
|
||||
"@types/ws": "^8.18.1",
|
||||
"tslib": "2.8.1",
|
||||
"ws": "^8.18.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@supabase/realtime-js/node_modules/ws": {
|
||||
"version": "8.18.3",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz",
|
||||
"integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": ">=5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@supabase/storage-js": {
|
||||
"version": "2.89.0",
|
||||
"resolved": "https://registry.npmjs.org/@supabase/storage-js/-/storage-js-2.89.0.tgz",
|
||||
"integrity": "sha512-6zKcXofk/M/4Eato7iqpRh+B+vnxeiTumCIP+Tz26xEqIiywzD9JxHq+udRrDuv6hXE+pmetvJd8n5wcf4MFRQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"iceberg-js": "^0.8.1",
|
||||
"tslib": "2.8.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@supabase/supabase-js": {
|
||||
"version": "2.89.0",
|
||||
"resolved": "https://registry.npmjs.org/@supabase/supabase-js/-/supabase-js-2.89.0.tgz",
|
||||
"integrity": "sha512-KlaRwSfFA0fD73PYVMHj5/iXFtQGCcX7PSx0FdQwYEEw9b2wqM7GxadY+5YwcmuEhalmjFB/YvqaoNVF+sWUlg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@supabase/auth-js": "2.89.0",
|
||||
"@supabase/functions-js": "2.89.0",
|
||||
"@supabase/postgrest-js": "2.89.0",
|
||||
"@supabase/realtime-js": "2.89.0",
|
||||
"@supabase/storage-js": "2.89.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/cors": {
|
||||
"version": "2.8.19",
|
||||
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.19.tgz",
|
||||
@@ -28,6 +129,21 @@
|
||||
"undici-types": "~7.16.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/phoenix": {
|
||||
"version": "1.6.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/phoenix/-/phoenix-1.6.7.tgz",
|
||||
"integrity": "sha512-oN9ive//QSBkf19rfDv45M7eZPi0eEXylht2OLEXicu5b4KoQ1OzXIw+xDSGWxSxe1JmepRR/ZH283vsu518/Q==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/ws": {
|
||||
"version": "8.18.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.1.tgz",
|
||||
"integrity": "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/accepts": {
|
||||
"version": "1.3.8",
|
||||
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
|
||||
@@ -676,6 +792,15 @@
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/iceberg-js": {
|
||||
"version": "0.8.1",
|
||||
"resolved": "https://registry.npmjs.org/iceberg-js/-/iceberg-js-0.8.1.tgz",
|
||||
"integrity": "sha512-1dhVQZXhcHje7798IVM+xoo/1ZdVfzOMIc8/rgVSijRK38EDqOJoGula9N/8ZI5RD8QTxNQtK/Gozpr+qUqRRA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/iconv-lite": {
|
||||
"version": "0.4.24",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||
@@ -1567,6 +1692,12 @@
|
||||
"nodetouch": "bin/nodetouch.js"
|
||||
}
|
||||
},
|
||||
"node_modules/tslib": {
|
||||
"version": "2.8.1",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
|
||||
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
|
||||
"license": "0BSD"
|
||||
},
|
||||
"node_modules/type-is": {
|
||||
"version": "1.6.18",
|
||||
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
|
||||
|
||||
147
setup-apache.sh
147
setup-apache.sh
@@ -1,147 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Automated Apache Configuration Script for Connect-5
|
||||
# This script configures Apache to proxy requests to the Node.js server
|
||||
|
||||
set -e # Exit on error
|
||||
|
||||
echo "🔧 Connect-5 Apache Configuration Script"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Check if running as root
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo -e "${RED}❌ This script must be run as root (use sudo)${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Step 1: Enabling Apache modules..."
|
||||
a2enmod proxy 2>/dev/null || echo "proxy already enabled"
|
||||
a2enmod proxy_http 2>/dev/null || echo "proxy_http already enabled"
|
||||
a2enmod proxy_wstunnel 2>/dev/null || echo "proxy_wstunnel already enabled"
|
||||
a2enmod rewrite 2>/dev/null || echo "rewrite already enabled"
|
||||
echo -e "${GREEN}✅ Apache modules enabled${NC}"
|
||||
echo ""
|
||||
|
||||
echo "Step 2: Finding Apache configuration file..."
|
||||
# Try to find the SSL config file
|
||||
CONFIG_FILE=""
|
||||
|
||||
# Check common locations
|
||||
if [ -f "/etc/apache2/sites-available/connect5-le-ssl.conf" ]; then
|
||||
CONFIG_FILE="/etc/apache2/sites-available/connect5-le-ssl.conf"
|
||||
elif [ -f "/etc/apache2/sites-available/connect5.conf" ]; then
|
||||
CONFIG_FILE="/etc/apache2/sites-available/connect5.conf"
|
||||
elif [ -f "/etc/apache2/sites-available/000-default-le-ssl.conf" ]; then
|
||||
CONFIG_FILE="/etc/apache2/sites-available/000-default-le-ssl.conf"
|
||||
elif [ -f "/etc/apache2/sites-available/default-ssl.conf" ]; then
|
||||
CONFIG_FILE="/etc/apache2/sites-available/default-ssl.conf"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Could not auto-detect config file${NC}"
|
||||
echo "Available config files:"
|
||||
ls -1 /etc/apache2/sites-available/
|
||||
echo ""
|
||||
read -p "Enter the full path to your Apache config file: " CONFIG_FILE
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}✅ Using config file: $CONFIG_FILE${NC}"
|
||||
echo ""
|
||||
|
||||
echo "Step 3: Backing up original config..."
|
||||
cp "$CONFIG_FILE" "${CONFIG_FILE}.backup.$(date +%Y%m%d_%H%M%S)"
|
||||
echo -e "${GREEN}✅ Backup created${NC}"
|
||||
echo ""
|
||||
|
||||
echo "Step 4: Checking if proxy rules already exist..."
|
||||
if grep -q "ProxyPass /api" "$CONFIG_FILE"; then
|
||||
echo -e "${YELLOW}⚠️ Proxy rules already exist in config file${NC}"
|
||||
echo "Skipping modification to avoid duplicates."
|
||||
else
|
||||
echo "Adding proxy configuration..."
|
||||
|
||||
# Create the proxy configuration
|
||||
PROXY_CONFIG="
|
||||
# Connect-5 Node.js Proxy Configuration
|
||||
ProxyPreserveHost On
|
||||
ProxyPass /api http://localhost:3000/api
|
||||
ProxyPassReverse /api http://localhost:3000/api
|
||||
ProxyPass /socket.io http://localhost:3000/socket.io
|
||||
ProxyPassReverse /socket.io http://localhost:3000/socket.io
|
||||
|
||||
# WebSocket support
|
||||
RewriteEngine On
|
||||
RewriteCond %{HTTP:Upgrade} =websocket [NC]
|
||||
RewriteRule /(.*) ws://localhost:3000/\$1 [P,L]
|
||||
"
|
||||
|
||||
# Insert before the closing </VirtualHost> tag
|
||||
sed -i "/<\/VirtualHost>/i\\$PROXY_CONFIG" "$CONFIG_FILE"
|
||||
|
||||
echo -e "${GREEN}✅ Proxy configuration added${NC}"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "Step 5: Testing Apache configuration..."
|
||||
if apache2ctl configtest 2>&1 | grep -q "Syntax OK"; then
|
||||
echo -e "${GREEN}✅ Apache configuration is valid${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Apache configuration has errors!${NC}"
|
||||
echo "Restoring backup..."
|
||||
cp "${CONFIG_FILE}.backup."* "$CONFIG_FILE"
|
||||
echo "Please check the configuration manually."
|
||||
exit 1
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "Step 6: Restarting Apache..."
|
||||
systemctl restart apache2
|
||||
echo -e "${GREEN}✅ Apache restarted${NC}"
|
||||
echo ""
|
||||
|
||||
echo "Step 7: Checking if Node.js server is running..."
|
||||
if pgrep -f "node server.js" > /dev/null; then
|
||||
echo -e "${GREEN}✅ Node.js server is running${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Node.js server is not running${NC}"
|
||||
echo "Starting Node.js server..."
|
||||
cd /home/github2/apps/app-connect5
|
||||
nohup node server.js > server.log 2>&1 &
|
||||
sleep 2
|
||||
echo -e "${GREEN}✅ Node.js server started${NC}"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "Step 8: Testing API endpoint..."
|
||||
sleep 2
|
||||
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" https://connect5.beyondcloud.technology/api/db-status)
|
||||
|
||||
if [ "$HTTP_CODE" = "200" ]; then
|
||||
echo -e "${GREEN}✅ API endpoint is working! (HTTP $HTTP_CODE)${NC}"
|
||||
echo ""
|
||||
echo "📊 Database Status:"
|
||||
curl -s https://connect5.beyondcloud.technology/api/db-status | python3 -m json.tool 2>/dev/null || curl -s https://connect5.beyondcloud.technology/api/db-status
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ API endpoint returned HTTP $HTTP_CODE${NC}"
|
||||
echo "This might take a moment for DNS/cache to update."
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "=========================================="
|
||||
echo -e "${GREEN}🎉 Configuration Complete!${NC}"
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo "1. Visit https://connect5.beyondcloud.technology/"
|
||||
echo "2. Check that the status bar shows 'Connected'"
|
||||
echo "3. Test multiplayer functionality"
|
||||
echo ""
|
||||
echo "Logs:"
|
||||
echo " Apache: sudo tail -f /var/log/apache2/error.log"
|
||||
echo " Node.js: tail -f /home/github2/apps/app-connect5/server.log"
|
||||
echo ""
|
||||
echo "Backup saved to: ${CONFIG_FILE}.backup.*"
|
||||
echo "=========================================="
|
||||
@@ -1,182 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Automated Nginx Configuration for CloudSticks
|
||||
# Specifically for /etc/nginx-cs/ setup
|
||||
|
||||
set -e # Exit on error
|
||||
|
||||
echo "🔧 Connect-5 CloudSticks Nginx Configuration"
|
||||
echo "=============================================="
|
||||
echo ""
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Check if running as root
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo -e "${RED}❌ This script must be run as root (use sudo)${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# CloudSticks uses /etc/nginx-cs/
|
||||
CONFIG_FILE="/etc/nginx-cs/nginx.conf"
|
||||
|
||||
echo "Step 1: Checking CloudSticks Nginx configuration..."
|
||||
if [ ! -f "$CONFIG_FILE" ]; then
|
||||
echo -e "${RED}❌ CloudSticks Nginx config not found at $CONFIG_FILE${NC}"
|
||||
exit 1
|
||||
fi
|
||||
echo -e "${GREEN}✅ Found config: $CONFIG_FILE${NC}"
|
||||
echo ""
|
||||
|
||||
echo "Step 2: Backing up original config..."
|
||||
cp "$CONFIG_FILE" "${CONFIG_FILE}.backup.$(date +%Y%m%d_%H%M%S)"
|
||||
echo -e "${GREEN}✅ Backup created${NC}"
|
||||
echo ""
|
||||
|
||||
echo "Step 3: Checking if proxy rules already exist..."
|
||||
if grep -q "proxy_pass.*3000" "$CONFIG_FILE"; then
|
||||
echo -e "${YELLOW}⚠️ Proxy rules already exist${NC}"
|
||||
echo "Skipping modification to avoid duplicates."
|
||||
else
|
||||
echo "Adding proxy configuration to nginx.conf..."
|
||||
|
||||
# Create the proxy configuration block
|
||||
cat > /tmp/nginx_proxy.conf << 'EOF'
|
||||
|
||||
# Connect-5 API Proxy
|
||||
location /api {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Connect-5 Socket.io Proxy
|
||||
location /socket.io {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
EOF
|
||||
|
||||
# Find the server block for port 443 and insert before its closing brace
|
||||
# Look for the last } in a server block listening on 443
|
||||
if grep -q "listen.*443" "$CONFIG_FILE"; then
|
||||
# Insert proxy config before the closing brace of the SSL server block
|
||||
awk '
|
||||
/listen.*443/ { in_ssl_block=1 }
|
||||
in_ssl_block && /^[[:space:]]*}[[:space:]]*$/ && !done {
|
||||
while ((getline line < "/tmp/nginx_proxy.conf") > 0) {
|
||||
print line
|
||||
}
|
||||
close("/tmp/nginx_proxy.conf")
|
||||
done=1
|
||||
}
|
||||
{ print }
|
||||
' "$CONFIG_FILE" > /tmp/nginx_modified.conf
|
||||
|
||||
mv /tmp/nginx_modified.conf "$CONFIG_FILE"
|
||||
rm /tmp/nginx_proxy.conf
|
||||
|
||||
echo -e "${GREEN}✅ Proxy configuration added${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Could not find SSL server block (port 443)${NC}"
|
||||
echo "You may need to add the proxy configuration manually."
|
||||
cat /tmp/nginx_proxy.conf
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "Step 4: Testing Nginx configuration..."
|
||||
if nginx -t 2>&1 | grep -q "successful\|syntax is ok"; then
|
||||
echo -e "${GREEN}✅ Nginx configuration is valid${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Nginx configuration has errors!${NC}"
|
||||
echo "Restoring backup..."
|
||||
cp "${CONFIG_FILE}.backup."* "$CONFIG_FILE" 2>/dev/null || true
|
||||
nginx -t
|
||||
exit 1
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "Step 5: Reloading Nginx..."
|
||||
systemctl reload nginx 2>/dev/null || service nginx reload 2>/dev/null || nginx -s reload
|
||||
echo -e "${GREEN}✅ Nginx reloaded${NC}"
|
||||
echo ""
|
||||
|
||||
echo "Step 6: Checking Node.js server..."
|
||||
if pgrep -f "node server.js" > /dev/null; then
|
||||
PID=$(pgrep -f "node server.js")
|
||||
echo -e "${GREEN}✅ Node.js server is running (PID: $PID)${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Node.js server not running${NC}"
|
||||
echo "Starting Node.js server..."
|
||||
cd /home/github2/apps/app-connect5
|
||||
nohup node server.js > server.log 2>&1 &
|
||||
sleep 3
|
||||
if pgrep -f "node server.js" > /dev/null; then
|
||||
echo -e "${GREEN}✅ Node.js server started${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Failed to start Node.js server${NC}"
|
||||
echo "Check server.log for errors"
|
||||
fi
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "Step 7: Testing endpoints..."
|
||||
sleep 2
|
||||
|
||||
# Test local endpoint
|
||||
echo "Testing local endpoint..."
|
||||
LOCAL_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/api/db-status 2>/dev/null || echo "000")
|
||||
if [ "$LOCAL_CODE" = "200" ]; then
|
||||
echo -e "${GREEN}✅ Local Node.js server responding (HTTP $LOCAL_CODE)${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Local server returned HTTP $LOCAL_CODE${NC}"
|
||||
fi
|
||||
|
||||
# Test production endpoint
|
||||
echo "Testing production endpoint..."
|
||||
PROD_CODE=$(curl -s -o /dev/null -w "%{http_code}" https://connect5.beyondcloud.technology/api/db-status 2>/dev/null || echo "000")
|
||||
if [ "$PROD_CODE" = "200" ]; then
|
||||
echo -e "${GREEN}✅ Production endpoint working! (HTTP $PROD_CODE)${NC}"
|
||||
echo ""
|
||||
echo "📊 Database Status:"
|
||||
curl -s https://connect5.beyondcloud.technology/api/db-status 2>/dev/null | python3 -m json.tool 2>/dev/null || curl -s https://connect5.beyondcloud.technology/api/db-status
|
||||
elif [ "$PROD_CODE" = "000" ]; then
|
||||
echo -e "${YELLOW}⚠️ Could not connect to production URL${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Production returned HTTP $PROD_CODE${NC}"
|
||||
echo "May need a moment for changes to propagate..."
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "=============================================="
|
||||
echo -e "${GREEN}🎉 Setup Complete!${NC}"
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo "1. Visit: https://connect5.beyondcloud.technology/"
|
||||
echo "2. Status bar should show 'Connected'"
|
||||
echo "3. Test multiplayer functionality"
|
||||
echo ""
|
||||
echo "Logs:"
|
||||
echo " Nginx: sudo tail -f /var/log/nginx/error.log"
|
||||
echo " Node.js: tail -f /home/github2/apps/app-connect5/server.log"
|
||||
echo ""
|
||||
echo "Config backup: ${CONFIG_FILE}.backup.*"
|
||||
echo "=============================================="
|
||||
@@ -1,163 +0,0 @@
|
||||
#!/bin/bash
|
||||
# CloudSticks Nginx Setup - Handles custom nginx paths
|
||||
|
||||
set -e
|
||||
|
||||
echo "🔧 CloudSticks Nginx Proxy Setup"
|
||||
echo "================================="
|
||||
echo ""
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m'
|
||||
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo -e "${RED}❌ Run with sudo${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CONFIG_FILE="/etc/nginx-cs/nginx.conf"
|
||||
|
||||
echo "Step 1: Backing up config..."
|
||||
cp "$CONFIG_FILE" "${CONFIG_FILE}.backup.$(date +%Y%m%d_%H%M%S)"
|
||||
echo -e "${GREEN}✅ Backup created${NC}"
|
||||
echo ""
|
||||
|
||||
echo "Step 2: Creating proxy configuration..."
|
||||
mkdir -p /etc/nginx-cs/conf.d
|
||||
|
||||
cat > /etc/nginx-cs/conf.d/connect5-proxy.conf << 'EOF'
|
||||
# Connect-5 Proxy Configuration
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name connect5.beyondcloud.technology;
|
||||
|
||||
root /home/github2/apps/app-connect5;
|
||||
index index.html;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location /api {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location /socket.io {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
echo -e "${GREEN}✅ Proxy config created${NC}"
|
||||
echo ""
|
||||
|
||||
echo "Step 3: Finding nginx command..."
|
||||
NGINX_CMD=""
|
||||
if command -v nginx &> /dev/null; then
|
||||
NGINX_CMD="nginx"
|
||||
elif [ -f "/usr/sbin/nginx" ]; then
|
||||
NGINX_CMD="/usr/sbin/nginx"
|
||||
elif [ -f "/usr/local/sbin/nginx" ]; then
|
||||
NGINX_CMD="/usr/local/sbin/nginx"
|
||||
elif [ -f "/opt/cloudsticks/nginx/sbin/nginx" ]; then
|
||||
NGINX_CMD="/opt/cloudsticks/nginx/sbin/nginx"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Could not find nginx command${NC}"
|
||||
echo "Trying to reload via systemctl..."
|
||||
fi
|
||||
|
||||
if [ -n "$NGINX_CMD" ]; then
|
||||
echo "Testing config with: $NGINX_CMD"
|
||||
if $NGINX_CMD -t 2>&1 | grep -q "successful\|syntax is ok"; then
|
||||
echo -e "${GREEN}✅ Config valid${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Config error${NC}"
|
||||
$NGINX_CMD -t
|
||||
rm /etc/nginx-cs/conf.d/connect5-proxy.conf
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "Step 4: Reloading Nginx..."
|
||||
if systemctl reload nginx 2>/dev/null; then
|
||||
echo -e "${GREEN}✅ Reloaded via systemctl${NC}"
|
||||
elif service nginx reload 2>/dev/null; then
|
||||
echo -e "${GREEN}✅ Reloaded via service${NC}"
|
||||
elif [ -n "$NGINX_CMD" ]; then
|
||||
$NGINX_CMD -s reload 2>/dev/null && echo -e "${GREEN}✅ Reloaded via nginx -s${NC}" || echo -e "${YELLOW}⚠️ Could not reload${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Please restart nginx manually${NC}"
|
||||
echo "Try: systemctl restart nginx"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "Step 5: Checking Node.js..."
|
||||
if pgrep -f "node server.js" > /dev/null; then
|
||||
PID=$(pgrep -f "node server.js")
|
||||
echo -e "${GREEN}✅ Node.js running (PID: $PID)${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Starting Node.js...${NC}"
|
||||
cd /home/github2/apps/app-connect5
|
||||
nohup node server.js > server.log 2>&1 &
|
||||
sleep 2
|
||||
if pgrep -f "node server.js" > /dev/null; then
|
||||
echo -e "${GREEN}✅ Node.js started${NC}"
|
||||
fi
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "Step 6: Testing endpoints..."
|
||||
sleep 3
|
||||
|
||||
LOCAL=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/api/db-status 2>/dev/null || echo "000")
|
||||
echo "Local (localhost:3000): HTTP $LOCAL"
|
||||
|
||||
if [ "$LOCAL" = "200" ]; then
|
||||
echo -e "${GREEN}✅ Node.js server is responding${NC}"
|
||||
fi
|
||||
|
||||
PROD=$(curl -s -o /dev/null -w "%{http_code}" https://connect5.beyondcloud.technology/api/db-status 2>/dev/null || echo "000")
|
||||
echo "Production: HTTP $PROD"
|
||||
|
||||
if [ "$PROD" = "200" ]; then
|
||||
echo -e "${GREEN}✅ Production is working!${NC}"
|
||||
echo ""
|
||||
echo "Database Status:"
|
||||
curl -s https://connect5.beyondcloud.technology/api/db-status 2>/dev/null | python3 -m json.tool 2>/dev/null || curl -s https://connect5.beyondcloud.technology/api/db-status
|
||||
elif [ "$PROD" = "502" ]; then
|
||||
echo -e "${YELLOW}⚠️ 502 Bad Gateway - Nginx is proxying but Node.js might not be ready${NC}"
|
||||
elif [ "$PROD" = "404" ]; then
|
||||
echo -e "${YELLOW}⚠️ 404 - Nginx might need manual restart${NC}"
|
||||
echo "Try: sudo systemctl restart nginx"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "================================="
|
||||
echo -e "${GREEN}🎉 Setup Complete!${NC}"
|
||||
echo ""
|
||||
echo "Config file: /etc/nginx-cs/conf.d/connect5-proxy.conf"
|
||||
echo "Visit: https://connect5.beyondcloud.technology/"
|
||||
echo ""
|
||||
echo "If not working, try:"
|
||||
echo " sudo systemctl restart nginx"
|
||||
echo " tail -f /home/github2/apps/app-connect5/server.log"
|
||||
echo "================================="
|
||||
183
setup-nginx.sh
183
setup-nginx.sh
@@ -1,183 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Automated Nginx Configuration Script for Connect-5 on CloudSticks
|
||||
# Ubuntu 24.04 / Nginx
|
||||
|
||||
set -e # Exit on error
|
||||
|
||||
echo "🔧 Connect-5 Nginx Configuration Script"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Check if running as root
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo -e "${RED}❌ This script must be run as root (use sudo)${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Step 1: Finding Nginx configuration file..."
|
||||
CONFIG_FILE=""
|
||||
|
||||
# Check common CloudSticks/Nginx locations
|
||||
if [ -f "/etc/nginx/sites-available/connect5.beyondcloud.technology" ]; then
|
||||
CONFIG_FILE="/etc/nginx/sites-available/connect5.beyondcloud.technology"
|
||||
elif [ -f "/etc/nginx/sites-available/connect5" ]; then
|
||||
CONFIG_FILE="/etc/nginx/sites-available/connect5"
|
||||
elif [ -f "/etc/nginx/sites-available/default" ]; then
|
||||
CONFIG_FILE="/etc/nginx/sites-available/default"
|
||||
elif [ -f "/etc/nginx/conf.d/connect5.conf" ]; then
|
||||
CONFIG_FILE="/etc/nginx/conf.d/connect5.conf"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Could not auto-detect config file${NC}"
|
||||
echo "Available Nginx config files:"
|
||||
ls -1 /etc/nginx/sites-available/ 2>/dev/null || echo "No sites-available directory"
|
||||
ls -1 /etc/nginx/conf.d/ 2>/dev/null || echo "No conf.d directory"
|
||||
echo ""
|
||||
|
||||
# Try to find by domain name
|
||||
FOUND=$(grep -l "connect5.beyondcloud.technology\|beyondcloud.technology" /etc/nginx/sites-available/* /etc/nginx/conf.d/* 2>/dev/null | head -1)
|
||||
if [ -n "$FOUND" ]; then
|
||||
CONFIG_FILE="$FOUND"
|
||||
echo -e "${GREEN}✅ Found config by domain: $CONFIG_FILE${NC}"
|
||||
else
|
||||
read -p "Enter the full path to your Nginx config file: " CONFIG_FILE
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}✅ Using config file: $CONFIG_FILE${NC}"
|
||||
echo ""
|
||||
|
||||
echo "Step 2: Backing up original config..."
|
||||
cp "$CONFIG_FILE" "${CONFIG_FILE}.backup.$(date +%Y%m%d_%H%M%S)"
|
||||
echo -e "${GREEN}✅ Backup created${NC}"
|
||||
echo ""
|
||||
|
||||
echo "Step 3: Checking if proxy rules already exist..."
|
||||
if grep -q "proxy_pass.*3000" "$CONFIG_FILE"; then
|
||||
echo -e "${YELLOW}⚠️ Proxy rules already exist in config file${NC}"
|
||||
echo "Skipping modification to avoid duplicates."
|
||||
else
|
||||
echo "Adding proxy configuration..."
|
||||
|
||||
# Create a temporary file with the proxy configuration
|
||||
cat > /tmp/nginx_proxy_config.txt << 'EOF'
|
||||
# Connect-5 Node.js Proxy Configuration
|
||||
location /api {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location /socket.io {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
EOF
|
||||
|
||||
# Insert before the last closing brace
|
||||
# Find the last server block and insert before its closing brace
|
||||
if grep -q "server {" "$CONFIG_FILE"; then
|
||||
# Insert before the last closing brace of server block
|
||||
sed -i '/^[[:space:]]*}[[:space:]]*$/i\ # Connect-5 Proxy Config' "$CONFIG_FILE"
|
||||
sed -i '/# Connect-5 Proxy Config/r /tmp/nginx_proxy_config.txt' "$CONFIG_FILE"
|
||||
sed -i '/# Connect-5 Proxy Config/d' "$CONFIG_FILE"
|
||||
else
|
||||
echo -e "${RED}❌ Could not find server block in config${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm /tmp/nginx_proxy_config.txt
|
||||
|
||||
echo -e "${GREEN}✅ Proxy configuration added${NC}"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "Step 4: Testing Nginx configuration..."
|
||||
if nginx -t 2>&1 | grep -q "successful"; then
|
||||
echo -e "${GREEN}✅ Nginx configuration is valid${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Nginx configuration has errors!${NC}"
|
||||
echo "Restoring backup..."
|
||||
cp "${CONFIG_FILE}.backup."* "$CONFIG_FILE"
|
||||
echo "Please check the configuration manually."
|
||||
nginx -t
|
||||
exit 1
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "Step 5: Reloading Nginx..."
|
||||
systemctl reload nginx
|
||||
echo -e "${GREEN}✅ Nginx reloaded${NC}"
|
||||
echo ""
|
||||
|
||||
echo "Step 6: Checking if Node.js server is running..."
|
||||
if pgrep -f "node server.js" > /dev/null; then
|
||||
echo -e "${GREEN}✅ Node.js server is running${NC}"
|
||||
PID=$(pgrep -f "node server.js")
|
||||
echo " Process ID: $PID"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Node.js server is not running${NC}"
|
||||
echo "Starting Node.js server..."
|
||||
cd /home/github2/apps/app-connect5
|
||||
nohup node server.js > server.log 2>&1 &
|
||||
sleep 2
|
||||
echo -e "${GREEN}✅ Node.js server started${NC}"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "Step 7: Testing API endpoint..."
|
||||
sleep 2
|
||||
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" https://connect5.beyondcloud.technology/api/db-status 2>/dev/null || echo "000")
|
||||
|
||||
if [ "$HTTP_CODE" = "200" ]; then
|
||||
echo -e "${GREEN}✅ API endpoint is working! (HTTP $HTTP_CODE)${NC}"
|
||||
echo ""
|
||||
echo "📊 Database Status:"
|
||||
curl -s https://connect5.beyondcloud.technology/api/db-status 2>/dev/null | python3 -m json.tool 2>/dev/null || curl -s https://connect5.beyondcloud.technology/api/db-status
|
||||
elif [ "$HTTP_CODE" = "000" ]; then
|
||||
echo -e "${YELLOW}⚠️ Could not connect to server${NC}"
|
||||
echo "Testing local endpoint..."
|
||||
LOCAL_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/api/db-status 2>/dev/null || echo "000")
|
||||
if [ "$LOCAL_CODE" = "200" ]; then
|
||||
echo -e "${GREEN}✅ Local endpoint works (HTTP $LOCAL_CODE)${NC}"
|
||||
echo "The proxy might need a moment to update."
|
||||
else
|
||||
echo -e "${RED}❌ Node.js server not responding${NC}"
|
||||
fi
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ API endpoint returned HTTP $HTTP_CODE${NC}"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "=========================================="
|
||||
echo -e "${GREEN}🎉 Configuration Complete!${NC}"
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo "1. Visit https://connect5.beyondcloud.technology/"
|
||||
echo "2. Check that the status bar shows 'Connected'"
|
||||
echo "3. Test multiplayer functionality"
|
||||
echo ""
|
||||
echo "Logs:"
|
||||
echo " Nginx: sudo tail -f /var/log/nginx/error.log"
|
||||
echo " Node.js: tail -f /home/github2/apps/app-connect5/server.log"
|
||||
echo ""
|
||||
echo "Backup saved to: ${CONFIG_FILE}.backup.*"
|
||||
echo "=========================================="
|
||||
Reference in New Issue
Block a user