diff options
| author | Comzyh <[email protected]> | 2019-10-14 21:42:41 +0800 |
|---|---|---|
| committer | Haishan <[email protected]> | 2019-10-14 21:47:12 +0800 |
| commit | 9568e050f1be6151fc9fd51c195fd58a5a3d3d4f (patch) | |
| tree | b6acd25cdc09f97ddc84c873dea809bdfad08725 /src | |
| parent | 666c603128b90721a1f106cbf54052159e2e1f15 (diff) | |
Detect clash API server at `/` when log in. (#258)
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/APIConfig.js | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/components/APIConfig.js b/src/components/APIConfig.js index 236bd1d..42753da 100644 --- a/src/components/APIConfig.js +++ b/src/components/APIConfig.js @@ -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 => { |
