34 lines
939 B
Dart
34 lines
939 B
Dart
import 'package:flutter/foundation.dart' show kIsWeb;
|
|
|
|
const String _apiBaseUrlFromEnvironment = String.fromEnvironment(
|
|
'API_BASE_URL',
|
|
defaultValue: 'http://localhost:3000',
|
|
);
|
|
|
|
bool _isLocalDevHost(String host) {
|
|
final String h = host.toLowerCase();
|
|
return h == 'localhost' || h == '127.0.0.1';
|
|
}
|
|
|
|
/// Base URL for the Cyber Hybrid Hub API (Postgres-backed).
|
|
///
|
|
/// Local: `flutter run --dart-define=API_BASE_URL=http://localhost:3000`
|
|
///
|
|
/// Production web (https://cyberhybridhub.com): always [Uri.base.origin] so
|
|
/// /v1 and /hubs hit HAProxy on :443 — never :3000 over HTTP (mixed content).
|
|
String get apiBaseUrl {
|
|
if (!kIsWeb) {
|
|
return _apiBaseUrlFromEnvironment;
|
|
}
|
|
|
|
final Uri page = Uri.base;
|
|
if (_isLocalDevHost(page.host)) {
|
|
return _apiBaseUrlFromEnvironment;
|
|
}
|
|
|
|
return page.origin;
|
|
}
|
|
|
|
/// SignalR hub for real-time incoming questions.
|
|
String get questionsHubUrl => '$apiBaseUrl/hubs/questions';
|