From f6955e34489c79f6d5b764cb6a39b1387366b433 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Sun, 8 Nov 2026 21:56:29 +0100 Subject: Phase 0: project scaffolding - server/: Dart game-server package (shelf + WebSocket) with the hello/welcome handshake, ping/pong, error responses, healthz, static SPA serving with SPA fallback, and smoke tests (5/5) - web/: Svelte 5 + TypeScript SPA with the protocol client, connection-status page, vitest and svelte-check; Vite dev server proxies /ws to the Dart server - game data assets copied from the read-only reference app into server/assets/ (data, images, i18n, fonts, testData) - PLAN.md implementation plan and progress tracker; README rewritten for the web app; AGPLv3 LICENSE inherited from the reference app; .gitignore; scripts/ci.sh (full pipeline) - CLAUDE.md project guidance Verified: scripts/ci.sh passes end-to-end; live smoke confirms the server serves the built SPA at / and answers a WebSocket hello with a welcome message. --- server/bin/main.dart | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 server/bin/main.dart (limited to 'server/bin') diff --git a/server/bin/main.dart b/server/bin/main.dart new file mode 100644 index 0000000..67b8898 --- /dev/null +++ b/server/bin/main.dart @@ -0,0 +1,61 @@ +/// X-Haven web server entry point. +/// +/// Usage (from the server/ directory): +/// dart run bin/main.dart +/// dart run bin/main.dart --port 8080 --static-dir ../web/dist +library; + +import 'dart:io'; + +import 'package:x_haven_server/net/app.dart'; + +Future main(List args) async { + final port = _parseInt(args, 'port') ?? + int.tryParse(Platform.environment['PORT'] ?? '') ?? + 4567; + final staticDir = _parseString(args, 'static-dir') ?? '../web/dist'; + + final server = await startServer(port: port, staticDir: staticDir); + stdout + ..writeln('X-Haven server listening on http://localhost:${server.port}') + ..writeln('WebSocket endpoint: ws://localhost:${server.port}/ws'); + stdout.writeln('Static dir: ${_resolve(staticDir)}'); + + ProcessSignal.sigint + .watch() + .listen((_) async { + await server.close(force: true); + exit(0); + }); +} + +int? _parseInt(List args, String name) => + _parse(args, name, int.tryParse); + +String? _parseString(List args, String name) => + _parse(args, name, (String value) => value); + +T? _parse(List args, String name, T? Function(String) convert) { + for (var i = 0; i < args.length; i++) { + final arg = args[i]; + if (arg == '--$name') { + if (i + 1 >= args.length) { + stderr.writeln('Missing value for --$name'); + exit(64); + } + return convert(args[++i]); + } + if (arg.startsWith('--$name=')) { + return convert(arg.substring(arg.indexOf('=') + 1)); + } + } + return null; +} + +String _resolve(String path) { + try { + return Directory(path).absolute.path; + } catch (_) { + return path; + } +} -- cgit v1.3.1