6. Run and prove the finished game
Start the application you assembled:
npm run build
npm startVisit http://localhost:8181/login in two separate browser profiles. Sign in as Alice and Bob, join the same room, and take turns. The first account becomes X and the second O.
There is no handwritten game browser controller. Redweb serves the redweb-client live runtime, sends the typed commands from the TSX bindings, and applies private server-rendered updates over /match.
Try the failure and recovery paths too:
- Attempt an occupied square and a move from the wrong player.
- Open a second tab for one account; presence still counts that identity once.
- Disconnect Bob; Alice sees the presence change.
- Reconnect and resume Bob's reserved seat.
- Submit an old revision; the server rejects it rather than replaying an uncertain move.
- Sign out; every session and live game connection for that account closes.
Operational limits stay separate
Add the bounded transport policy in src/transport.ts:
import type { SocketRouteConfig } from 'redweb';
import type { AccountLookup } from './players.js';
/** Operational choices kept separate from the game's commands and rules. */
export function matchOptions(account: AccountLookup, origins: (origin: string | undefined) => boolean) {
return {
path: '/match',
admission: { authenticate: request => account(request) ?? false, origins },
orderedMessages: true, allowDuplicateConnections: true, logger: null,
heartbeat: { intervalMs: 15000, timeoutMs: 10000 },
websocketOptions: { maxPayload: 4096 },
rooms: { maxRooms: 100, maxMembersPerRoom: 100, maxRoomsPerConnection: 1 },
limits: { maxConnections: 100, maxPendingMessages: 16, maxBufferedBytes: 65536,
messageRate: { capacity: 20, refillPerSecond: 5, action: 'disconnect' } },
} satisfies Omit<SocketRouteConfig, 'handlers'>;
}Room membership is delivery state, not durable match storage. The tutorial caps connections and rooms, but the application still needs explicit expiry and persistence policies for production.
If you need a non-HTML frontend, add the optional adapter in src/raw-client.ts:
import type { GamePageState } from './players.js';
/** Optional compatibility for non-HTML clients. The TSX game does not need this adapter. */
export const rawClient = {
update: (state: Partial<GamePageState>) => ({ type: 'state', payload: state.game }),
reject: (text: string) => ({ type: 'notice', payload: { text } }),
};The TSX game does not use this adapter. Raw clients subscribe to state and await a correlated redweb:result; a pushed state update is not command completion.
Run the evidence
npm test
npm run test:coverage
npm run test:browserThe tests use actual HTTP, WebSockets, SQLite, password hashing, and headed Chrome—no mocked transports. They cover rules, malformed commands, unauthorized clients, private projection, full rooms, two-player moves, reconnects, presence, retained form input, logout, and optional raw-client requests.
Know the boundary
Accounts persist in SQLite, but matches are bounded, single-process, and in memory. Room names are public identifiers, not invitations. Before public production use, add durable matches, invitations, abandoned-room eviction, account recovery, proxy abuse controls, backups, and monitoring.
Finished: the project grew in one direction—from server rules to validated commands, connected players, server TSX, authentication, one application lifecycle, and real acceptance tests.
Download the complete project Setup, optional configuration, and limits