feat: change api framework to angel3.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import 'package:angel3_configuration/angel3_configuration.dart';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:angel3_jinja/angel3_jinja.dart';
|
||||
import 'package:file/file.dart';
|
||||
import 'plugins/plugins.dart' as plugins;
|
||||
|
||||
/// This is a perfect place to include configuration and load plug-ins.
|
||||
AngelConfigurer configureServer(FileSystem fileSystem) {
|
||||
return (Angel app) async {
|
||||
// Load configuration from the `config/` directory.
|
||||
//
|
||||
// See: https://github.com/angel-dart/configuration
|
||||
await app.configure(configuration(fileSystem));
|
||||
|
||||
// Configure our application to render jinja templates from the `views/` directory.
|
||||
//
|
||||
// See: https://github.com/angel-dart/jinja
|
||||
await app.configure(jinja(path: fileSystem.directory('views').path));
|
||||
|
||||
// Apply another plug-ins, i.e. ones that *you* have written.
|
||||
//
|
||||
// Typically, the plugins in `lib/src/config/plugins/plugins.dart` are plug-ins
|
||||
// that add functionality specific to your application.
|
||||
//
|
||||
// If you write a plug-in that you plan to use again, or are
|
||||
// using one created by the community, include it in
|
||||
// `lib/src/config/config.dart`.
|
||||
await plugins.configureServer(app);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'dart:async';
|
||||
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:postgres/postgres.dart';
|
||||
|
||||
Future<void> configureServer(Angel app) async {
|
||||
var connection = await connectToPostgres(app.configuration);
|
||||
await connection.open();
|
||||
|
||||
var logger = app.environment.isProduction ? null : app.logger;
|
||||
var executor = PostgreSqlExecutor(connection, logger: logger);
|
||||
|
||||
app
|
||||
..container!.registerSingleton<QueryExecutor>(executor)
|
||||
..shutdownHooks.add((_) => connection.close());
|
||||
}
|
||||
|
||||
Future<PostgreSQLConnection> connectToPostgres(Map configuration) async {
|
||||
var postgresConfig = configuration['postgres'] as Map? ?? {};
|
||||
var connection = PostgreSQLConnection(
|
||||
postgresConfig['host'] as String? ?? 'localhost',
|
||||
postgresConfig['port'] as int? ?? 5432,
|
||||
postgresConfig['database_name'] as String? ??
|
||||
Platform.environment['USER'] ??
|
||||
Platform.environment['USERNAME'] ??
|
||||
'',
|
||||
username: postgresConfig['username'] as String?,
|
||||
password: postgresConfig['password'] as String?,
|
||||
timeZone: postgresConfig['time_zone'] as String? ?? 'UTC',
|
||||
timeoutInSeconds: postgresConfig['timeout_in_seconds'] as int? ?? 30,
|
||||
useSSL: postgresConfig['use_ssl'] as bool? ?? false);
|
||||
return connection;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import 'dart:async';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'orm.dart' as orm;
|
||||
|
||||
Future configureServer(Angel app) async {
|
||||
// Include any plugins you have made here.
|
||||
await app.configure(orm.configureServer);
|
||||
}
|
||||
Reference in New Issue
Block a user