╔═══════════════════════════════════════════════════════════════════╗ ║ CloudLinux Node.js - Production Diagnostic ║ ╚═══════════════════════════════════════════════════════════════════╝ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1. Current Git Branch & Status ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ * main afb7701 Remove .env files from .gitignore and add restart guide 4738528 Remove node_modules from Git and update .gitignore 0615e22 Update cloudlinux-diagnostic.sh ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2. Check if CORS is in server.js ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ✅ CORS import found ✅ CORS middleware found ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3. First 30 lines of server.js ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ // ATTENTION! If you customize this file, please create a backup of this file. // This file will get overwritten on every update. const nearbuy = require('./lib/index-new.js'); const path = require('path'); const { v4 } = require('uuid'); const express = require('express'); const cors = require('cors'); const os = require('os'); const app = express(); // ======================================== // CRITICAL: CORS Configuration // ======================================== // Parse CORS_ORIGIN from environment variable const corsOrigin = process.env.CORS_ORIGIN ? process.env.CORS_ORIGIN.split(',').map(origin => origin.trim()) : '*'; console.log('🔒 CORS enabled for origins:', corsOrigin); // Apply CORS middleware to ALL routes app.use(cors({ origin: corsOrigin, methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], credentials: true, allowedHeaders: ['Content-Type', 'Authorization'] })); app.use(express.json()); ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4. Check .env file for CORS_ORIGIN ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ✅ CORS_ORIGIN found in .env: CORS_ORIGIN=https://nearbuymarts.com,https://www.nearbuymarts.com,https://cloud.nearbuymarts.com,https://api.nearbuymarts.com,https://v1.nearbuymarts.com,http://nearbuymarts.com,http://www.nearbuymarts.com Complete .env contents: # ============================================ # PRODUCTION .ENV FOR CPANEL NODE.JS SERVER # ============================================ # Upload this file to: /home/username/nearbuy-api/nearbuy-server/.env # Then restart PM2: pm2 restart nearbuymarts-api # Database Configuration DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=nearbuymarts_cloudserver DB_USERNAME=nearbuymarts_cloudserver DB_PASSWORD=nearbuymarts_cloudserver # Server Configuration PORT=3000 NODE_ENV=production APP_URL=https://nearbuymarts.com # Security Configuration # IMPORTANT: Generate a strong token using: node -e "console.log(require('crypto').randomBytes(32).toString('hex'))" ADMIN_SECRET_TOKEN=66730bb3a0d8c8ddd26e56faa3ff349508002c18f41b3a01e888ec252f89df1d # ============================================ # CRITICAL: CORS Configuration for Socket.IO # ============================================ # This MUST include ALL domains that will connect to Socket.IO # Each domain must include the protocol (http:// or https://) # Separate multiple domains with commas (NO spaces after commas) # # ⚠️ IMPORTANT: Your Laravel admin is at https://nearbuymarts.com # So this domain MUST be in the CORS_ORIGIN list! # ============================================ CORS_ORIGIN=https://nearbuymarts.com,https://www.nearbuymarts.com,https://cloud.nearbuymarts.com,https://api.nearbuymarts.com,https://v1.nearbuymarts.com,http://nearbuymarts.com,http://www.nearbuymarts.com # Logging LOG_LEVEL=info # WhatsApp Web Version WA_VERSION=[2,3000,1021163342] # Socket.IO Configuration SOCKET_IO_PATH=/socket.io # Baileys Configuration (optional) ## RECORD_MESSAGES=text,media ## AUTOREPLY_BACK_MENU="back" ## MOBILE=true ## DISABLE_DEVICE_INFO=true ## DISABLE_GET_QR=true ## DISABLE_SERVER_INFO=true ## DEVICE_BROWSER='["NearBuyMarts-API", "Safari", "10.0"]' # ProxyScrape (optional) ## PROXYSCRAPE="https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=us&ssl=no&anonymity=elite" ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5. Check CloudLinux Node.js App Status ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ CloudLinux Selector found: {"available_versions": {"14.21.2": {"base_dir": "/opt/alt/alt-nodejs14", "status": "enabled"}, "16.20.2": {"base_dir": "/opt/alt/alt-nodejs16", "status": "enabled"}, "18.20.8": {"base_dir": "/opt/alt/alt-nodejs18", "status": "enabled"}, "19.9.0": {"base_dir": "/opt/alt/alt-nodejs19", "status": "enabled"}, "20.19.4": {"base_dir": "/opt/alt/alt-nodejs20", "status": "enabled", "users": {"nearbuymarts": {"applications": {"apis.nearbuymarts.com": {"app_mode": "production", "app_status": "started", "app_uri": "", "config_files": ["package.json"], "domain": "api.nearbuymarts.com", "env_vars": {}, "passenger_log_file": null, "startup_file": "server.js", "virtualenv": {"activate_path": "/home/nearbuymarts/nodevenv/apis.nearbuymarts.com/20/bin/activate"}}}, "homedir": "/home/nearbuymarts"}}}, "22.18.0": {"base_dir": "/opt/alt/alt-nodejs22", "status": "enabled", "users": {"nearbuymarts": {"applications": {"cloud.nearbuymarts.com": {"app_mode": "production", "app_status": "started", "app_uri": "", "config_files": ["package.json"], "domain": "cloud.nearbuymarts.com", "env_vars": {}, "passenger_log_file": null, "startup_file": "server.js", "virtualenv": {"activate_path": "/home/nearbuymarts/nodevenv/cloud.nearbuymarts.com/22/bin/activate"}}, "v2.nearbuymarts.com": {"app_mode": "production", "app_status": "stopped", "app_uri": "", "config_files": ["package.json"], "domain": "v2.nearbuymarts.com", "env_vars": {}, "passenger_log_file": null, "startup_file": "server.js", "virtualenv": {"activate_path": "/home/nearbuymarts/nodevenv/v2.nearbuymarts.com/22/bin/activate"}}}, "homedir": "/home/nearbuymarts"}}}, "24.6.0": {"base_dir": "/opt/alt/alt-nodejs24", "status": "enabled"}}, "cache_status": "ready", "default_version": "20", "passenger_active": true, "result": "success", "selector_enabled": true, "timestamp": 1763093607.5518713} ❌ Node.js process NOT running! ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6. Check Application Logs ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ No standard CloudLinux Node.js log found Check cPanel > CloudLinux Node.js App > Log ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7. Test Server Response ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Testing https://cloud.nearbuymarts.com/socket.io/?EIO=4&transport=polling % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 2a06:98c1:3121::3:443... * Connected to cloud.nearbuymarts.com (2a06:98c1:3121::3) port 443 (#0) * ALPN, offering h2 * ALPN, offering http/1.1 * CAfile: /etc/pki/tls/certs/ca-bundle.crt * TLSv1.0 (OUT), TLS header, Certificate Status (22): } [5 bytes data] * TLSv1.3 (OUT), TLS handshake, Client hello (1): } [512 bytes data] * TLSv1.2 (IN), TLS header, Certificate Status (22): { [5 bytes data] * TLSv1.3 (IN), TLS handshake, Server hello (2): { [122 bytes data] * TLSv1.2 (IN), TLS header, Finished (20): { [5 bytes data] * TLSv1.2 (IN), TLS header, Unknown (23): { [5 bytes data] * TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8): { [19 bytes data] * TLSv1.3 (IN), TLS handshake, Certificate (11): { [2547 bytes data] * TLSv1.3 (IN), TLS handshake, CERT verify (15): { [79 bytes data] * TLSv1.3 (IN), TLS handshake, Finished (20): { [52 bytes data] * TLSv1.2 (OUT), TLS header, Finished (20): } [5 bytes data] * TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1): ╔═══════════════════════════════════════════════════════════════════╗ ║ Diagnostic Complete ║ ╚═══════════════════════════════════════════════════════════════════╝ 🔍 Analysis: ✅ Code and configuration look correct If still getting 400 errors: 1. Restart app via cPanel > CloudLinux Node.js App 2. Check if environment variables are set in cPanel interface 3. Clear browser cache completely