GAME ROOM RELAY - setup on cPanel ("Setup Node.js App") ======================================================== The website (gamesite.skillneer.com) handles login and the lobby. This relay is the small always-on program that passes game messages between you and your brother. It has no dependencies, so there is nothing to npm install. It needs Node 18 or newer. We give it its own subdomain: relay.skillneer.com STEP 1 - make the subdomain --------------------------- cPanel > Domains (or Subdomains) > create relay.skillneer.com (The document root it asks for can be anything, e.g. relay_public. Nothing is served from it.) Then cPanel > SSL/TLS Status > Run AutoSSL so relay.skillneer.com gets HTTPS. HTTPS is required: browsers refuse a plain ws:// connection from an https website. STEP 2 - upload the relay ------------------------- Upload relay-upload.zip to your home folder and unzip it into a NEW folder named game-relay (in your home folder, NOT inside public_html). You should end up with game-relay/server.js. STEP 3 - create the Node.js app ------------------------------- cPanel > Software > Setup Node.js App > Create Application Node.js version ........ 18 or higher (20 if offered) Application mode ....... Production Application root ....... game-relay Application URL ........ relay.skillneer.com (leave the path after it empty) Application startup file server.js Click Create. On the same page, under "Environment variables", add these two (values are in relay.env): RELAY_SECRET (copy the value from relay.env; it must match the website's .env) RELAY_ALLOWED_ORIGINS https://gamesite.skillneer.com Save, then click Restart. Skip "Run NPM Install" - there is no dependency list to install. STEP 4 - check it is running ---------------------------- Open https://relay.skillneer.com/health in a browser. It should say: ok - A Passenger error page or 503? Open the app's log from the Node.js App page (or look for stderr.log in game-relay). "RELAY_SECRET is not set" means the variable wasn't saved. An old Node version also shows up there. STEP 5 - check that WebSockets get through (important) ------------------------------------------------------ Some hosts accept normal pages but block WebSocket upgrades. Test from the Terminal app on your Mac: curl -i -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Sec-WebSocket-Version: 13" -H "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==" "https://relay.skillneer.com/ws?t=test" Look at the first line of the answer: - HTTP/1.1 401 Unauthorized -> GOOD. The relay answered the WebSocket request itself (401 is correct: "test" is not a real login token). - anything else (200, 400, 404, 502, 503, a web page) -> your host does not pass WebSockets through to Node. Two-player can't run on this host; use a small VPS or a Docker platform instead (see "Other ways" below). STEP 6 - tell the website where the relay is -------------------------------------------- Edit the website's .env (gamesite folder; in File Manager turn on "Show hidden files"). Set: RELAY_INTERNAL_URL=https://relay.skillneer.com RELAY_PUBLIC_WS=wss://relay.skillneer.com/ws Save. Reload https://gamesite.skillneer.com : the "server offline" banner should be gone. (If bootstrap/cache/config.php exists on the server, delete it so the new .env is read.) STEP 7 - play ------------- You: open the lobby, host a game. Brother: signed in on his own device, the game lights up, Join. IF SOMETHING SEEMS OFF ---------------------- - Games work for a while, then rooms vanish: the host may be recycling the Node process when idle, or running more than one copy. Rooms live in memory, so the app must run as ONE process. The lobby keeps it awake while someone has it open. If it keeps happening, use "Other ways". - "Server offline" in the lobby but /health says ok: RELAY_INTERNAL_URL in the website .env is wrong, or RELAY_SECRET differs between the two places. - Joining fails with a server-unreachable message: RELAY_PUBLIC_WS is wrong or the Step 5 check failed. - Changing RELAY_SECRET later means changing it in BOTH places, then restarting the Node app. OTHER WAYS (only if cPanel can't do it) --------------------------------------- Settings are the same environment variables: RELAY_SECRET, RELAY_ALLOWED_ORIGINS, and PORT (set by platforms). - A small VPS: install Node 18+ and Caddy, upload this folder, run it with pm2, and give Caddy: relay.skillneer.com { reverse_proxy 127.0.0.1:3100 } (run with RELAY_BIND=127.0.0.1 PORT=3100). Caddy gets the HTTPS certificate by itself. - A Docker/Node platform (Render, Fly.io, Railway): create a web service from this folder (it has a Dockerfile), add the two variables. Free plans may sleep when idle. Then do Step 6 with that address instead. Security: nobody can connect without a login token signed by the website, so a public relay address is fine. Keep RELAY_SECRET private.