sojorn/sojorn_app/lib/config/api_config.dart

33 lines
1,018 B
Dart

class ApiConfig {
// Not const so we can normalize away accidentally-configured http/8080 URLs.
static final String baseUrl = _computeBaseUrl();
static String _computeBaseUrl() {
final raw = const String.fromEnvironment(
'API_BASE_URL',
defaultValue: 'https://api.sojorn.net/api/v1',
);
// Auto-upgrade any lingering http://api.sojorn.net:8080 (or plain http)
// to the public https endpoint behind nginx. This protects old .env files
// or cached web builds that still point at the closed port 8080.
if (raw.startsWith('http://api.sojorn.net:8080')) {
return raw.replaceFirst(
'http://api.sojorn.net:8080',
'https://api.sojorn.net',
);
}
// Belt-and-suspenders: Force migration even if args/env are stale
if (raw.contains('gosojorn.com')) {
return raw.replaceAll('gosojorn.com', 'sojorn.net');
}
if (raw.startsWith('http://')) {
return 'https://${raw.substring('http://'.length)}';
}
return raw;
}
}