56 lines
1.7 KiB
Dart
56 lines
1.7 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:dotenv/dotenv.dart';
|
|
|
|
class ServerEnv {
|
|
ServerEnv._({
|
|
required this.databaseUrl,
|
|
required this.port,
|
|
required this.firebaseWebApiKey,
|
|
required this.questionWorkerEnabled,
|
|
required this.questionWorkerIntervalSeconds,
|
|
required this.questionPipelineTestMode,
|
|
});
|
|
|
|
final String databaseUrl;
|
|
final int port;
|
|
final String firebaseWebApiKey;
|
|
final bool questionWorkerEnabled;
|
|
final int questionWorkerIntervalSeconds;
|
|
final bool questionPipelineTestMode;
|
|
|
|
static ServerEnv load() {
|
|
final DotEnv env = DotEnv(includePlatformEnvironment: true)
|
|
..load(['.env']);
|
|
|
|
final String? databaseUrl = env['DATABASE_URL'];
|
|
if (databaseUrl == null || databaseUrl.isEmpty) {
|
|
stderr.writeln('DATABASE_URL is required in server/.env');
|
|
exit(1);
|
|
}
|
|
|
|
final String? apiKey = env['FIREBASE_WEB_API_KEY'];
|
|
if (apiKey == null || apiKey.isEmpty) {
|
|
stderr.writeln('FIREBASE_WEB_API_KEY is required in server/.env');
|
|
exit(1);
|
|
}
|
|
|
|
final int port = int.tryParse(env['PORT'] ?? '3000') ?? 3000;
|
|
final bool workerEnabled =
|
|
(env['QUESTION_WORKER_ENABLED'] ?? 'true').toLowerCase() != 'false';
|
|
final int workerIntervalSeconds =
|
|
int.tryParse(env['QUESTION_WORKER_INTERVAL_SECONDS'] ?? '60') ?? 60;
|
|
final bool pipelineTestMode =
|
|
(env['QUESTION_PIPELINE_TEST_MODE'] ?? 'false').toLowerCase() == 'true';
|
|
|
|
return ServerEnv._(
|
|
databaseUrl: databaseUrl,
|
|
port: port,
|
|
firebaseWebApiKey: apiKey,
|
|
questionWorkerEnabled: workerEnabled,
|
|
questionWorkerIntervalSeconds: workerIntervalSeconds,
|
|
questionPipelineTestMode: pipelineTestMode,
|
|
);
|
|
}
|
|
}
|