Redo #258: if / is api server, use it as default (#624)

This commit is contained in:
Comzyh 2021-07-19 21:54:02 +08:00 committed by GitHub
parent c78dbcf8f8
commit 0058e1765b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,7 +11,7 @@ import Field from './Field';
import { connect } from './StateProvider';
import SvgYacd from './SvgYacd';
const { useState, useRef, useCallback } = React;
const { useState, useRef, useCallback, useEffect } = React;
const Ok = 0;
const mapState = (s: State) => ({
@ -69,6 +69,20 @@ function APIConfig({ dispatch }) {
[onConfirm]
);
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') {
setBaseURL(window.location.origin)
}
});
};
useEffect(() => {
detectApiServer();
}, []);
return (
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
<div className={s0.root} ref={contentEl} onKeyDown={handleContentOnKeyDown}>