-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.dart
More file actions
30 lines (24 loc) · 802 Bytes
/
main.dart
File metadata and controls
30 lines (24 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import 'dart:io';
import 'package:dart_frog/dart_frog.dart';
import 'package:dotenv/dotenv.dart';
import 'package:mongo_dart/mongo_dart.dart';
Future<Db> initDb() async {
String? mongodbPw;
if (File('.env').existsSync()) {
final env = DotEnv(includePlatformEnvironment: true, quiet: true)..load();
mongodbPw = env['MONGODB_PW'];
} else {
mongodbPw = Platform.environment['MONGODB_PW'];
}
final db = await Db.create(
'mongodb+srv://mongodb:$mongodbPw@budgetizer.yere7rm.mongodb.net/budgetizer',
);
// ignore: avoid_print
print('Initialized database');
await db.open();
return db;
}
Future<HttpServer> run(Handler handler, InternetAddress ip, int port) async {
final db = await initDb();
return serve(handler.use(provider<Db>((context) => db)), ip, port);
}