Просмотр исходного кода

Auto-remove trailing slash and other unwanted errors from Nightscout URL

When users enter a trailing / in their Nightscout URL (Eg: "https://url/" rather than "https://url"), this will immediately result in a "Not found!" (404) error, because a / is already being appended. (Resulting in "https://url//").

This check removes the trailing slash to prevent 404's.
Liroy van Hoewijk 2 лет назад
Родитель
Сommit
f902c73c44

+ 4 - 0
FreeAPS/Sources/Modules/NightscoutConfig/NightscoutConfigStateModel.swift

@@ -49,6 +49,10 @@ extension NightscoutConfig {
         }
 
         func connect() {
+           if let CheckURL = url.last, CheckURL == "/" {
+                  let fixedURL = url.dropLast()
+                  url = String(fixedURL)
+              }        
             guard let url = URL(string: url) else {
                 message = "Invalid URL"
                 return