Skip to content

Commit

Permalink
fix: .well-known
Browse files Browse the repository at this point in the history
  • Loading branch information
waclaw66 committed Mar 4, 2025
1 parent 6398489 commit 56ec7a5
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions mobile/lib/services/api.service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@ class ApiService implements Authentication {
/// port - optional (default: based on schema)
/// path - optional
Future<String> resolveEndpoint(String serverUrl) async {
final url = sanitizeUrl(serverUrl);

if (!await _isEndpointAvailable(serverUrl)) {
throw ApiException(503, "Server is not reachable");
}
String url = sanitizeUrl(serverUrl);

// Check for /.well-known/immich
final wellKnownEndpoint = await _getWellKnownEndpoint(url);
if (wellKnownEndpoint.isNotEmpty) return wellKnownEndpoint;
if (wellKnownEndpoint.isNotEmpty) {
url = sanitizeUrl(wellKnownEndpoint);
}

if (!await _isEndpointAvailable(url)) {
throw ApiException(503, "Server is not reachable");
}

// Otherwise, assume the URL provided is the api endpoint
return url;
Expand Down Expand Up @@ -128,10 +130,12 @@ class ApiService implements Authentication {
var headers = {"Accept": "application/json"};
headers.addAll(getRequestHeaders());

final res = await client.get(
Uri.parse("$baseUrl/.well-known/immich"),
headers: headers,
);
final res = await client
.get(
Uri.parse("$baseUrl/.well-known/immich"),
headers: headers,
)
.timeout(const Duration(seconds: 5));

if (res.statusCode == 200) {
final data = jsonDecode(res.body);
Expand Down

0 comments on commit 56ec7a5

Please sign in to comment.