Detect clash API server at / when log in. (#258)

This commit is contained in:
Comzyh 2019-10-14 21:42:41 +08:00 committed by Haishan
parent 666c603128
commit 9568e050f1

View file

@ -21,8 +21,21 @@ function APIConfig2() {
const actions = useActions({ updateClashAPIConfig }); const actions = useActions({ updateClashAPIConfig });
const contentEl = useRef(null); const contentEl = useRef(null);
const detectApiServer = async () => {
// if there is already a clash API server at `/`, just use it as default value
const res = await fetch('/');
res.json().then(data => {
if (data['hello'] === 'clash') {
setHostname(window.location.hostname);
setPort(window.location.port);
}
});
};
useEffect(() => { useEffect(() => {
contentEl.current.focus(); contentEl.current.focus();
detectApiServer();
}, []); }, []);
const handleInputOnChange = e => { const handleInputOnChange = e => {