diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2026-11-08 21:56:29 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2026-11-08 21:56:29 +0100 |
| commit | f6955e34489c79f6d5b764cb6a39b1387366b433 (patch) | |
| tree | 83dad99ad81964036820468ad23fdc9ebe5c20a5 /server/bin/main.dart | |
| parent | 0578ed0e5a08e6790a2e02416c4bf79f8c471f2d (diff) | |
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.
Diffstat (limited to 'server/bin/main.dart')
| -rw-r--r-- | server/bin/main.dart | 61 |
1 files changed, 61 insertions, 0 deletions
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<void> main(List<String> 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<String> args, String name) => + _parse(args, name, int.tryParse); + +String? _parseString(List<String> args, String name) => + _parse(args, name, (String value) => value); + +T? _parse<T>(List<String> 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; + } +} |
