diff --git a/api/bin/dev.dart b/api/bin/dev.dart index 05028ae..86238c3 100644 --- a/api/bin/dev.dart +++ b/api/bin/dev.dart @@ -8,12 +8,11 @@ import 'package:logging/logging.dart'; void main() async { // Watch the config/ and web/ directories for changes, and hot-reload the server. - hierarchicalLoggingEnabled = true; - var hot = HotReloader(() async { - var logger = Logger.detached('dde_gesture_manager_api') + Logger.root ..level = Level.ALL ..onRecord.listen(prettyLog); + var logger = Logger.detached('dde_gesture_manager_api'); var app = Angel(logger: logger, reflector: MirrorsReflector()); await app.configure(configureServer); return app; @@ -23,6 +22,5 @@ void main() async { ]); var server = await hot.startServer('127.0.0.1', 3000); - print( - 'dde_gesture_manager_api server listening at http://${server.address.address}:${server.port}'); + print('dde_gesture_manager_api server listening at http://${server.address.address}:${server.port}'); } diff --git a/api/lib/src/config/plugins/orm.dart b/api/lib/src/config/plugins/orm.dart index be286f8..7b12623 100644 --- a/api/lib/src/config/plugins/orm.dart +++ b/api/lib/src/config/plugins/orm.dart @@ -3,11 +3,32 @@ import 'dart:io'; import 'package:angel3_framework/angel3_framework.dart'; import 'package:angel3_orm/angel3_orm.dart'; import 'package:angel3_orm_postgres/angel3_orm_postgres.dart'; +import 'package:logging/logging.dart'; import 'package:postgres/postgres.dart'; +const times = ['', 'st', 'nd', 'rd']; + +const retryTimeOut = Duration(seconds: 30); + Future configureServer(Angel app) async { - var connection = await connectToPostgres(app.configuration); - await connection.open(); + final _log = Logger('OrmPlugin'); + late PostgreSQLConnection connection; + var _startTime = DateTime.now(); + var _retry = 1; + while (_startTime.difference(DateTime.now()).abs() <= retryTimeOut) { + try { + connection = await connectToPostgres(app.configuration); + await connection.open(); + break; + } catch (e, st) { + await connection.close(); + _log.severe( + 'Failed to connect, the $_retry${_retry <= 3 ? times[_retry] : 'th'} retry will do in a second.', e, st); + sleep(Duration(seconds: 1)); + _retry++; + if (_startTime.difference(DateTime.now()).abs() > retryTimeOut) rethrow; + } + } var logger = app.environment.isProduction ? null : app.logger; var executor = PostgreSqlExecutor(connection, logger: logger); diff --git a/api/lib/src/routes/routes.dart b/api/lib/src/routes/routes.dart index a97b978..b481eaa 100644 --- a/api/lib/src/routes/routes.dart +++ b/api/lib/src/routes/routes.dart @@ -1,5 +1,6 @@ import 'package:angel3_framework/angel3_framework.dart'; import 'package:angel3_cors/angel3_cors.dart'; +import 'package:angel3_static/angel3_static.dart'; import 'package:file/file.dart'; import 'controllers/auth_controllers.dart' as auth_controllers; import 'controllers/system_controllers.dart' as system_controllers; @@ -28,6 +29,9 @@ AngelConfigurer configureServer(FileSystem fileSystem) { await app.configure(auth_controllers.configureServer); await app.configure(scheme_controllers.configureServer); + var vDir = VirtualDirectory(app, fileSystem, source: fileSystem.directory('web')); + app.fallback(vDir.handleRequest); + // Throw a 404 if no route matched the request. app.fallback((req, res) => throw AngelHttpException.notFound()); diff --git a/api/pubspec.yaml b/api/pubspec.yaml index ecc4afa..3f9dbe1 100644 --- a/api/pubspec.yaml +++ b/api/pubspec.yaml @@ -12,6 +12,7 @@ dependencies: angel3_orm: ^4.0.6 angel3_orm_postgres: ^3.3.0 angel3_serialize: ^4.1.0 + angel3_static: ^4.1.0 angel3_production: ^3.1.2 belatuk_pretty_logging: ^4.0.0 optional: ^6.0.0 diff --git a/api/views/layout.html b/api/views/layout.html index 2217499..cf17603 100644 --- a/api/views/layout.html +++ b/api/views/layout.html @@ -1,10 +1,13 @@ - - + + {% block title %}{% endblock %} - - - {% block body %}{% endblock %} - + + + + + +{% block body %}{% endblock %} + \ No newline at end of file diff --git a/api/web/css/site.css b/api/web/css/site.css index 9e40b8d..984ca32 100644 --- a/api/web/css/site.css +++ b/api/web/css/site.css @@ -1,27 +1,9 @@ html, body { height: 100%; -} - -body { - margin: 0; padding: 0; - width: 100%; - display: table; - font-weight: 100; - font-family: 'Lato', sans-serif; -} - -.container { - text-align: center; - display: table-cell; - vertical-align: middle; -} - -.content { - text-align: center; - display: inline-block; + margin: 0; } -.title { - font-size: 96px; +body { + margin: .5em; } \ No newline at end of file