From 8099fedf8266904e73b0e10c2752ae32966f0df5 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Sun, 1 Jan 2023 21:02:06 +0800 Subject: [PATCH] Don't store instances list inside JS bundle --- src/pages/login.jsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/pages/login.jsx b/src/pages/login.jsx index 63312d5c..d184ceaa 100644 --- a/src/pages/login.jsx +++ b/src/pages/login.jsx @@ -3,7 +3,7 @@ import './login.css'; import { useEffect, useRef, useState } from 'preact/hooks'; import Loader from '../components/loader'; -import instancesList from '../data/instances.json'; +import instancesListURL from '../data/instances.json?url'; import { getAuthorizationURL, registerApplication } from '../utils/auth'; import store from '../utils/store'; import useTitle from '../utils/useTitle'; @@ -14,6 +14,20 @@ function Login() { const cachedInstanceURL = store.local.get('instanceURL'); const [uiState, setUIState] = useState('default'); + const [instancesList, setInstancesList] = useState([]); + useEffect(() => { + (async () => { + try { + const res = await fetch(instancesListURL); + const data = await res.json(); + setInstancesList(data); + } catch (e) { + // Silently fail + console.error(e); + } + })(); + }, []); + useEffect(() => { if (cachedInstanceURL) { instanceURLRef.current.value = cachedInstanceURL.toLowerCase();