-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(mobile): auto api endpoint #15184
base: main
Are you sure you want to change the base?
feat(mobile): auto api endpoint #15184
Conversation
Label error. Requires exactly 1 of: changelog:.*. Found: 📱mobile. A maintainer will add the required label. |
@@ -94,6 +94,17 @@ class LoginForm extends HookConsumerWidget { | |||
); | |||
} | |||
|
|||
// Automatically add /api to serverUrl if missing | |||
serverUrl = serverUrl.trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally the input field just doesn't accept whitespace to begin with
if (serverUrl.endsWith('/api/')) { | ||
serverUrl = serverUrl.substring(0, serverUrl.length - 1); | ||
} else if (!serverUrl.endsWith('/api')) { | ||
serverUrl = '$serverUrl/api'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some .well-known endpoint autodiscovery code that already appends /api as one of the discovery steps, in https://github.com/immich-app/immich/blob/main/mobile/lib/services/api.service.dart.
Code Addition: Automatically Adjust
serverUrl
with/api
This code addition ensures that the
serverUrl
string is correctly formatted to include/api
at the end if it is missing, or remove any extra trailing slashes if the URL already ends with/api/
.Explanation
Trimming Whitespace:
The
serverUrl
is trimmed of any leading or trailing whitespace usingserverUrl.trim()
. This ensures there are no accidental spaces that could cause issues when checking or modifying the URL.Handling
/api/
and/api
:The logic checks if the
serverUrl
ends with/api/
. If it does, the trailing slash is removed to standardize the URL format.If the
serverUrl
does not end with/api
, the code appends/api
to the URL. This ensures that the URL always contains/api
at the end when needed.Example Workflow
serverUrl = "http://example.com/api/"
, it will be trimmed tohttp://example.com/api
.serverUrl = "http://example.com"
, it will be changed tohttp://example.com/api
.serverUrl = "http://example.com/api"
, it will remain unchanged.This addition helps prevent issues with inconsistent server URLs by ensuring they always contain the proper
/api
endpoint suffix. Additionally this alleviates confusion when inviting friends/family to use your Immich server and you wish to just share your server URL without the /api at the end.