?First, pick what you're shipping
Tower Duel can be deployed in two very different shapes. Choosing the right one decides everything else on this page.
- 🗂️ Static — only the built
dist/folder. Cheapest and simplest (GitHub Pages, Netlify…), but the connected TV + phones mode does not work: there is no server to run the match. - 🖧 Node server — runs
server/index.js, which serves the page and hosts the realtime WebSocket rooms. Required for the full multiscreen experience. This is what the Docker image ships.
1Build the bundle
Everything starts from one command. Vite compiles the source into a self-contained dist/ folder of HTML, JS and assets.
# install exactly the locked dependencies npm ci # compile the single-page bundle into dist/ npm run build
The Vite config uses base: './' (relative paths), so the result is portable: it works whether it's served from a domain root or a sub-path. To preview the built bundle locally:
# static preview (solo only) npm run preview # full Node server (page + realtime), on http://localhost:3000 npm start
npm start runs node server/index.js and serves dist/, so always npm run build first.2Wrap it in Docker
The repository ships a multi-stage Dockerfile. A first stage installs everything and builds the bundle; a second, slim stage keeps only the runtime dependencies and the built files. Smaller image, no build tools in production.
# --- build stage: compile with Vite --- FROM node:24-alpine AS build WORKDIR /app COPY package*.json ./ RUN npm ci COPY . . RUN npm run build # --- runtime stage: Node (SPA + WebSocket rooms) --- FROM node:24-alpine WORKDIR /app ENV NODE_ENV=production RUN npm ci --omit=dev COPY --from=build /app/dist ./dist EXPOSE 3000 CMD ["node", "server/index.js"]
Build the image, then run it:
# build the image (the trailing dot = current folder) docker build -t tower-duel . # run it: map host port 8088 to the container's 3000 docker run --rm -p 8088:3000 -e PUBLIC_HOST=192.168.1.20 tower-duel
Open http://localhost:8088. For phones to join they need a reachable address — but inside a container the auto-detected IP is the Docker bridge (e.g. 172.17.0.x), which phones can't reach. Set PUBLIC_HOST to the machine's LAN address (e.g. 192.168.1.20) so the QR code on the TV points somewhere reachable.
PORT (default 3000) and the optional PUBLIC_HOST (the host/IP advertised in the QR code) environment variables. The image also declares a HEALTHCHECK that pings /, so orchestrators can tell when the container is actually ready.3On a VPS (Docker + reverse proxy)
On your own server (a $5 VPS is plenty), run the container and put nginx in front to terminate HTTPS and forward traffic. The one thing you must not forget: WebSocket upgrade headers, or the realtime channel silently fails.
server {
listen 80;
server_name towerduel.example.com;
location / {
proxy_pass http://127.0.0.1:8088;
proxy_http_version 1.1;
# these two lines are what make WebSocket work
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
Then get a free HTTPS certificate (the browser requires wss:// on an HTTPS page):
sudo certbot --nginx -d towerduel.example.com
https:// page the WebSocket must be wss:// (secure). The client builds the URL from the current page, so serving the whole site over HTTPS is enough — no code change needed. Mixing http page + wss (or the reverse) is blocked by the browser.4Deploy on alwaysdata
alwaysdata runs a Node.js application directly, without Docker. The server serves the page and the WebSocket on the same origin — so there's nothing special to configure on the realtime side, and no client change (it builds wss://<host>/ws on its own from the page). No need to set up two separate sites like some tutorials do: a single Node site at the root is enough.
1) Get the code there (the simplest: the release bundle)
No need to build anything, neither locally nor on the server. Pull the pre-built bundle, published with every release, straight onto the server: the game is already compiled, so alwaysdata only needs to install express + ws. The URL is permanent and always serves the current version.
# over SSH on alwaysdata, go to your working directory cd ~/www/towerduel # download the release bundle (permanent URL → current version) wget https://github.com/1e1/tower-phaser/releases/latest/download/tower-duel-server.zip unzip tower-duel-server.zip # the game is already compiled # install express + ws only npm ci --omit=dev # NO vite, NO build
npm run package locally (build + zip into release/), upload the contents of release/tower-duel-<version>/ into your working directory, then carry on with the same npm ci --omit=dev.npm install / npm ci omits the devDependencies — including vite. If you deploy the raw git repo (without a pre-built dist/) and try npm run build in place, it fails for lack of vite. That's exactly what the release bundle avoids: it already ships dist/. Failing that, force npm ci --include=dev && npm run build to build on the server.2) Create the site (Web → Sites → Add a site)
In the admin panel, add a site and fill in:
- Type: Node.js.
- Command:
node server/index.js. - Working directory: the folder where
dist/lives (e.g.~/www/towerduel). - Node version: a recent LTS (18+).
- Idle time: 0. Without it, alwaysdata puts the app to sleep when idle; a page request wakes it, but a WebSocket upgrade does not wake the backend → the
wssfails with “can't establish connection”. Idle time = 0 keeps the process always alive.
Port: alwaysdata provides the PORT variable and the server already reads it — nothing to change. Domain & HTTPS: attach your (sub)domain, alwaysdata issues the certificate → page and WebSocket served over HTTPS/WSS automatically.
/ws, so no separate WebSocket service and no custom proxy. But: alproxy cuts idle connections after 300 s, and rooms live in memory inside that process. The server sends a heartbeat every 30 s to keep lobby sockets alive; and as long as you stay on a single instance, everyone lands on the same room registry. If the site grows and moves to several processes/instances, two players on different instances will no longer find each other (“room not found”) — you'll then need shared state (Redis…) or sticky sessions.5Container platforms (Fly.io, Render…)
Managed container hosts deploy the exact same Docker image, with WebSocket support out of the box.
- 🪰 Fly.io —
fly launchdetects theDockerfile; set the internal port to3000infly.toml, thenfly deploy. - 🟪 Render — create a Web Service from the repo, runtime Docker. Render injects
PORTand routes WebSocket traffic automatically.
6Static-only hosting (GitHub Pages, Netlify)
If you only want the solo, keyboard game, you can host the built files anywhere static — no server bill at all.
npm run build # then publish the contents of dist/ to your static host # (Netlify: drag & drop dist/, or set build = "npm run build", publish = "dist")
docs/ folder — that's static hosting in action, for documentation rather than the game.✓Troubleshooting checklist
- 🔌 Phones connect but the match never starts → the WebSocket isn't getting through. Check the
Upgrade/Connectionproxy headers. - 🔒 Console error about an insecure WebSocket → your page is HTTPS but the socket is
ws://. Serve the whole site over HTTPS so it becomeswss://. - 🚪 Container starts then exits / nothing on the port → the platform's
PORTdoesn't match what's exposed. Let the app readPORTand map ports correctly. - 📵 Phones can't reach the game on a LAN → you opened
localhost, or in Docker the auto-detected IP is the bridge address. Use the machine's LAN IP (shown in the server logs and the QR code) — in a container, setPUBLIC_HOST. - 🧩 404 on refresh of a sub-page → the SPA fallback to
index.htmlis missing. The Node server handles it; for static hosts, add a catch-all rewrite toindex.html. - 🔌 “can't establish connection to wss://…/ws” (the handshake fails right away) → the Node backend isn't answering the upgrade. Open
https://<host>/healthz: JSON with apid= Node is running (then check that idle time = 0); the game page or a 404 = the site isn't served by Node (fix the site type / command / working directory). - 🚪 “room not found” while everyone is on the same URL → either the room expired (the TV socket cut by the proxy after 300 s of inactivity — fixed by the heartbeat in ≥ v1.1.x), or the site runs across several instances (keep the process count at 1).