Files
noitu/web/vite.config.js
T
tiennm99 ffa13a0f6e feat(web): add online 1v1 play
Create a room and share a six-character code or an invite link; join by either.
The waiting room shows the code until an opponent arrives. During a game the
opponent's disconnection raises a banner with the grace countdown, and their
return clears it. When the game ends, the rematch prompt appears only while an
offer is actually open, so there is never a button that can only produce an
error.

The board is now one component both modes render, which is what makes online
play the same screen as the bot game rather than a second implementation of it.

Room codes are normalized by stripping separators and reading the code out of a
pasted invite link, and nothing else. Filtering out every character outside the
alphabet would turn any sentence into six plausible letters and send the player
to a room that was never theirs.

The socket now opens when the player asks for a room, not on arrival: the
handshake carries the nickname once, and a socket opened before they typed it
introduced them under whatever was stored beforehand. A tab that already holds
a session reconnects immediately instead, so refreshing mid-game returns to the
game. A resume the server cannot honour is dropped quietly rather than opening
the lobby with an error the player did nothing to cause.

The client also notices a socket that fails without closing. Nothing did
before, so the page kept showing a live connection and a running countdown over
a socket nothing could reach. A tick that fired late is ignored, because a
backgrounded tab has its timers throttled and would otherwise close a healthy
connection every time the player switched away.
2026-09-05 14:18:03 +07:00

33 lines
1.3 KiB
JavaScript

import { fileURLToPath } from 'node:url';
import { sveltekit } from '@sveltejs/kit/vite';
// vitest/config, not vite: the `test` block below is Vitest's, and vite's own
// config type does not know about it.
import { defineConfig } from 'vitest/config';
export default defineConfig({
plugins: [sveltekit()],
server: {
// Dev runs Vite and the Go binary on different ports, so the socket has
// to be proxied. That keeps the client's URL logic identical in both
// environments: it always connects to its own origin.
proxy: {
'/ws': { target: 'ws://localhost:8080', ws: true },
'/healthz': 'http://localhost:8080'
}
},
test: {
// The default node environment: the cross-language fixture test reads
// files through import.meta.url, which jsdom rewrites to an http URL.
// The two suites that need a DOM opt in with a per-file docblock.
// e2e/ is Playwright's; Vitest must not try to run browser specs.
include: ['tests/**/*.test.js'],
exclude: ['e2e/**', 'node_modules/**', 'build/**'],
// SvelteKit resolves $lib during a build, not under Vitest, so the test
// run needs the same mapping stated explicitly. It points at the same
// directory the framework uses, so there is one meaning of $lib.
alias: {
$lib: fileURLToPath(new URL('./src/lib', import.meta.url))
}
}
});