Detect clash API server at /
when log in. (#258)
This commit is contained in:
parent
666c603128
commit
9568e050f1
1 changed files with 13 additions and 0 deletions
|
@ -21,8 +21,21 @@ function APIConfig2() {
|
|||
const actions = useActions({ updateClashAPIConfig });
|
||||
|
||||
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(() => {
|
||||
contentEl.current.focus();
|
||||
detectApiServer();
|
||||
}, []);
|
||||
|
||||
const handleInputOnChange = e => {
|
||||
|
|
Loading…
Reference in a new issue