feat: 添加环境配置和动态主页URL
This commit is contained in:
32
lib/config/app_config.dart
Normal file
32
lib/config/app_config.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
enum Environment {
|
||||
production,
|
||||
}
|
||||
|
||||
class AppConfig {
|
||||
static const Environment currentEnvironment = Environment.production;
|
||||
|
||||
static final Map<Environment, List<String>> _environmentHosts = {
|
||||
Environment.production: [
|
||||
'h5-im.imharry.work',
|
||||
],
|
||||
};
|
||||
|
||||
static List<String> get environmentHosts {
|
||||
return _environmentHosts[currentEnvironment] ?? const [];
|
||||
}
|
||||
|
||||
static String get homeUrl {
|
||||
final host = environmentHosts.isNotEmpty
|
||||
? environmentHosts.first
|
||||
: 'h5-im.imharry.work';
|
||||
return _normalizeHomeUrl(host);
|
||||
}
|
||||
|
||||
static String _normalizeHomeUrl(String host) {
|
||||
final value = host.trim();
|
||||
if (value.startsWith('http://') || value.startsWith('https://')) {
|
||||
return value.endsWith('/') ? value : '$value/';
|
||||
}
|
||||
return 'https://$value/';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user