diff --git a/app/login.tsx b/app/login.tsx
index ec52bd1e..ad4c36d8 100644
--- a/app/login.tsx
+++ b/app/login.tsx
@@ -44,27 +44,8 @@ const Login: React.FC = () => {
useEffect(() => {
(async () => {
- // add a test that checks if the url contains http/https
- if (_apiUrl.startsWith("http") || _apiUrl.startsWith("https")) {
- {
- setServer({
- address: _apiUrl,
- });
- }
- } else {
- //check if url requires ssl
- // use curl to see if https is required
- // if not use http
- // if yes use https
- const test = fetch("http://jellyfin.oakgrove.site/web/#/home.html")
- .then((response) => console.log(response))
- .catch((error) => console.error(error));
-
- const test2 = fetch("https://jellyfin.oakgrove.site/web/#/home.html")
- .then((response) => console.log(response))
- .catch((error) => console.error(error));
- }
-
+ // we might re-use the checkUrl function here to check the url as well
+ // however, I don't think it should be necessary for now
if (_apiUrl) {
setServer({
address: _apiUrl,
@@ -99,12 +80,35 @@ const Login: React.FC = () => {
setLoading(false);
}
};
-
- const handleConnect = (url: string) => {
- if (!url.startsWith("http")) {
- Alert.alert("Error", "URL needs to start with http or https.");
- return;
+ async function checkUrl(url: string) {
+ // remove trailing / so we don't double add double / in my checker
+ if (url.endsWith("/")) {
+ url = url.slice(0, -1);
}
+
+ if( await fetch("https://" + url + "/web/#/home.html", {mode: 'cors'}).then((response) => {
+ return response.status;
+ }).catch((error) => {
+ console.log(error)
+ }) === 200) {
+ return "https://"+url
+ } else if (await fetch("http://" + url + "/web/#/home.html", {redirect: "manual"}).then((response) => {
+ return response.status;
+ }).catch((error) => {
+ console.log(error)
+ }) === 200) {
+ return "http://"+url
+ }
+ return undefined;
+ }
+
+ const handleConnect = async (url: string) => {
+ if (!url.startsWith("http")) {
+ const result = await checkUrl(url);
+ if (result === undefined) return;
+ url = result;
+ }
+ console.log(url);
setServer({ address: url.trim() });
};
@@ -239,11 +243,8 @@ const Login: React.FC = () => {
textContentType="URL"
maxLength={500}
/>
-
- Server URL requires http or https
-
-