Skip to content

Commit

Permalink
feat(server): Add About section
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustl22 committed Apr 30, 2024
1 parent ebfdbdc commit 86f5be8
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 20 deletions.
24 changes: 24 additions & 0 deletions wrestling_scoreboard_server/lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'dart:io';

import 'package:dotenv/dotenv.dart' show DotEnv;
import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:shelf_router/shelf_router.dart' as shelf_router;
Expand All @@ -17,8 +18,23 @@ import 'middleware/cors.dart';

final env = DotEnv();

Pubspec? pubspec;

Future<Pubspec> _parsePubspec() async {
if (pubspec == null) {
final file = File('pubspec.yaml');
if (await file.exists()) {
pubspec = Pubspec.parse(await file.readAsString());
} else {
throw FileSystemException('No file found', file.absolute.path);
}
}
return pubspec!;
}

Future init() async {
env.load(); // Load dotenv variables
await _parsePubspec();

// If the "PORT" environment variable is set, listen to it. Otherwise, 8080.
// https://cloud.google.com/run/docs/reference/container-contract#port
Expand Down Expand Up @@ -72,4 +88,12 @@ final _router = shelf_router.Router()
print('Error thrown by handler.\n$error');
return Response.internalServerError();
}
})
..mount('/about', (Request request) async {
final pubspec = await _parsePubspec();
return Response.ok('''
Name: ${pubspec.name}
Description: ${pubspec.description}
Version: ${pubspec.version}
''');
});
1 change: 1 addition & 0 deletions wrestling_scoreboard_server/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ <h1>Wrestling Scoreboard Server</h1>
<p>This app uses <a
href="https://pub.dev/packages/shelf_router">package:shelf_router</a> to define several code-based handlers:</p>
<ul>
<li><a href="/about">About</a></li>
<li><a href="/api">API Endpoint</a></li>
<ul>
<li><a href="/api/bout_configs">BoutConfigs</a></li>
Expand Down
56 changes: 36 additions & 20 deletions wrestling_scoreboard_server/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ packages:
dependency: transitive
description:
name: args
sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596
sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a"
url: "https://pub.dev"
source: hosted
version: "2.4.2"
version: "2.5.0"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -57,6 +57,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.1"
checked_yaml:
dependency: transitive
description:
name: checked_yaml
sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff
url: "https://pub.dev"
source: hosted
version: "2.0.3"
collection:
dependency: transitive
description:
Expand Down Expand Up @@ -125,10 +133,10 @@ packages:
dependency: transitive
description:
name: frontend_server_client
sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612"
sha256: f64a0333a82f30b0cca061bc3d143813a486dc086b574bfb233b7c1372427694
url: "https://pub.dev"
source: hosted
version: "3.2.0"
version: "4.0.0"
glob:
dependency: transitive
description:
Expand Down Expand Up @@ -189,10 +197,10 @@ packages:
dependency: transitive
description:
name: json_annotation
sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467
sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1"
url: "https://pub.dev"
source: hosted
version: "4.8.1"
version: "4.9.0"
lints:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -221,10 +229,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
sha256: "25dfcaf170a0190f47ca6355bdd4552cb8924b430512ff0cafb8db9bd41fe33b"
url: "https://pub.dev"
source: hosted
version: "1.12.0"
version: "1.14.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -277,10 +285,10 @@ packages:
dependency: "direct main"
description:
name: postgres
sha256: "69c93e9a7c69033eab766ba254f8266b417e3047d278ef6bc7aff01d58010c37"
sha256: bd1df6d2f4ad71aef92dc59e867e3ba9ec22cf2212a81cf9d35aa061ce80b1ae
url: "https://pub.dev"
source: hosted
version: "3.1.2"
version: "3.2.0"
pub_semver:
dependency: transitive
description:
Expand All @@ -289,6 +297,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
pubspec_parse:
dependency: "direct main"
description:
name: pubspec_parse
sha256: c63b2876e58e194e4b0828fcb080ad0e06d051cb607a6be51a9e084f47cb9367
url: "https://pub.dev"
source: hosted
version: "1.2.3"
sasl_scram:
dependency: transitive
description:
Expand Down Expand Up @@ -405,26 +421,26 @@ packages:
dependency: "direct dev"
description:
name: test
sha256: "7ee446762c2c50b3bd4ea96fe13ffac69919352bd3b4b17bac3f3465edc58073"
sha256: d72b538180efcf8413cd2e4e6fcc7ae99c7712e0909eb9223f9da6e6d0ef715f
url: "https://pub.dev"
source: hosted
version: "1.25.2"
version: "1.25.4"
test_api:
dependency: transitive
description:
name: test_api
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
sha256: "2419f20b0c8677b2d67c8ac4d1ac7372d862dc6c460cdbb052b40155408cd794"
url: "https://pub.dev"
source: hosted
version: "0.7.0"
version: "0.7.1"
test_core:
dependency: transitive
description:
name: test_core
sha256: "2bc4b4ecddd75309300d8096f781c0e3280ca1ef85beda558d33fcbedc2eead4"
sha256: "4d070a6bc36c1c4e89f20d353bfd71dc30cdf2bd0e14349090af360a029ab292"
url: "https://pub.dev"
source: hosted
version: "0.6.0"
version: "0.6.2"
typed_data:
dependency: transitive
description:
Expand All @@ -445,10 +461,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: a75f83f14ad81d5fe4b3319710b90dec37da0e22612326b696c9e1b8f34bbf48
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
url: "https://pub.dev"
source: hosted
version: "14.2.0"
version: "14.2.1"
watcher:
dependency: transitive
description:
Expand All @@ -469,10 +485,10 @@ packages:
dependency: "direct main"
description:
name: web_socket_channel
sha256: "1d8e795e2a8b3730c41b8a98a2dff2e0fb57ae6f0764a1c46ec5915387d257b2"
sha256: "58c6666b342a38816b2e7e50ed0f1e261959630becd4c879c4f26bfa14aa5a42"
url: "https://pub.dev"
source: hosted
version: "2.4.4"
version: "2.4.5"
webkit_inspection_protocol:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions wrestling_scoreboard_server/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies:
postgres: ^3.0.6
web_socket_channel: ^2.1.0
shelf_web_socket: ^1.0.3
pubspec_parse: ^1.2.3

dev_dependencies:
lints: ^3.0.0
Expand Down

0 comments on commit 86f5be8

Please sign in to comment.