diff options
| author | Hsiaoyi Hsu <[email protected]> | 2022-07-19 23:24:21 +0800 |
|---|---|---|
| committer | Hsiaoyi Hsu <[email protected]> | 2022-07-19 23:24:21 +0800 |
| commit | 92a06b982dd336949f481af2b9850b7e135d7c52 (patch) | |
| tree | 25db469d3974a84e3ada21f1df0f4744defc1fc9 /src | |
| parent | 3809a618453601fbdc3b488cdb0b76ba8ddfb0a7 (diff) | |
feat: auto append scheme for BaseURL
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/APIConfig.tsx | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/components/APIConfig.tsx b/src/components/APIConfig.tsx index 6e11bc4..1d7a88a 100644 --- a/src/components/APIConfig.tsx +++ b/src/components/APIConfig.tsx @@ -45,11 +45,24 @@ function APIConfig({ dispatch }) { }, []); const onConfirm = useCallback(() => { - verify({ baseURL, secret }).then((ret) => { + let unconfirmedBaseURL = baseURL; + if (unconfirmedBaseURL) { + const prefix = baseURL.substring(0, 7); + if (prefix.includes(':/')) { + // same logic in verify function + if (prefix !== 'http://' && prefix !== 'https:/') { + return [1, 'Must starts with http:// or https://']; + } + } else if (window.location.protocol) { + // only append scheme when prefix does not include scheme and current location includes scheme + unconfirmedBaseURL = `${window.location.protocol}//${unconfirmedBaseURL}`; + } + } + verify({ baseURL: unconfirmedBaseURL, secret }).then((ret) => { if (ret[0] !== Ok) { setErrMsg(ret[1]); } else { - dispatch(addClashAPIConfig({ baseURL, secret })); + dispatch(addClashAPIConfig({ baseURL: unconfirmedBaseURL, secret })); } }); }, [baseURL, secret, dispatch]); |
