fix: Update nginx config to use dynamic DNS resolution
- Replace upstream blocks with resolver directive - Use variables for backend addresses to avoid startup errors - Simplify configuration with single server block - Add health check endpoint
This commit is contained in:
@@ -12,7 +12,7 @@ class NanaxeServerService {
|
||||
|
||||
String? _baseUrl;
|
||||
String? _authToken;
|
||||
|
||||
|
||||
static const String _prefsUrlKey = 'nanaxe_server_url';
|
||||
static const String _prefsTokenKey = 'nanaxe_server_token';
|
||||
|
||||
@@ -25,9 +25,10 @@ class NanaxeServerService {
|
||||
|
||||
/// Настройка сервера
|
||||
Future<void> configure(String baseUrl, {String? token}) async {
|
||||
_baseUrl = baseUrl.replaceAll(RegExp(r'/+$'), ''); // Remove trailing slashes
|
||||
_baseUrl =
|
||||
baseUrl.replaceAll(RegExp(r'/+$'), ''); // Remove trailing slashes
|
||||
_authToken = token;
|
||||
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(_prefsUrlKey, _baseUrl!);
|
||||
if (token != null) {
|
||||
@@ -39,7 +40,7 @@ class NanaxeServerService {
|
||||
Future<void> clearConfiguration() async {
|
||||
_baseUrl = null;
|
||||
_authToken = null;
|
||||
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.remove(_prefsUrlKey);
|
||||
await prefs.remove(_prefsTokenKey);
|
||||
@@ -54,7 +55,8 @@ class NanaxeServerService {
|
||||
// ==================== AUTH ====================
|
||||
|
||||
/// Регистрация нового пользователя
|
||||
Future<Map<String, dynamic>> register(String email, String password, String username) async {
|
||||
Future<Map<String, dynamic>> register(
|
||||
String email, String password, String username) async {
|
||||
if (_baseUrl == null) throw Exception('Server not configured');
|
||||
|
||||
final response = await http.post(
|
||||
@@ -68,7 +70,7 @@ class NanaxeServerService {
|
||||
);
|
||||
|
||||
final data = jsonDecode(response.body);
|
||||
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
_authToken = data['token'];
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
@@ -93,7 +95,7 @@ class NanaxeServerService {
|
||||
);
|
||||
|
||||
final data = jsonDecode(response.body);
|
||||
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
_authToken = data['token'];
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
@@ -323,11 +325,11 @@ class NanaxeServerService {
|
||||
final headers = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
|
||||
if (_authToken != null) {
|
||||
headers['Authorization'] = 'Bearer $_authToken';
|
||||
}
|
||||
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user