2021-05-02 12:29:43 +00:00
|
|
|
import { RouteComponentProps } from '@reach/router';
|
2021-11-21 21:36:48 +00:00
|
|
|
import React from 'react';
|
2021-09-17 09:55:15 +00:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2021-05-02 12:29:43 +00:00
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
import { useModule } from '../../lib/react-utils';
|
|
|
|
import apiReducer, { modules } from '../../store/api/reducer';
|
2021-11-21 21:36:48 +00:00
|
|
|
import Field from '../components/Field';
|
2021-05-02 12:29:43 +00:00
|
|
|
|
|
|
|
export default function HTTPPage(
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
params: RouteComponentProps<unknown>,
|
|
|
|
): React.ReactElement {
|
2021-09-17 09:55:15 +00:00
|
|
|
const { t } = useTranslation();
|
2021-05-02 12:29:43 +00:00
|
|
|
const [httpConfig, setHTTPConfig] = useModule(modules.httpConfig);
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
2021-11-19 18:46:48 +00:00
|
|
|
const busy = httpConfig === null;
|
|
|
|
const active = httpConfig?.enable_static_server ?? false;
|
2021-05-02 12:29:43 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2021-09-17 09:55:15 +00:00
|
|
|
<h1 className="title is-4">{t('http.header')}</h1>
|
2021-11-21 21:36:48 +00:00
|
|
|
<Field name={t('http.server-bind')}>
|
2021-05-02 12:29:43 +00:00
|
|
|
<p className="control">
|
|
|
|
<input
|
|
|
|
disabled={busy}
|
|
|
|
className="input"
|
|
|
|
type="text"
|
2021-09-17 09:55:15 +00:00
|
|
|
placeholder=":8080"
|
2021-05-02 12:29:43 +00:00
|
|
|
value={httpConfig?.bind ?? ''}
|
|
|
|
onChange={(ev) =>
|
|
|
|
dispatch(
|
|
|
|
apiReducer.actions.httpConfigChanged({
|
|
|
|
...httpConfig,
|
|
|
|
bind: ev.target.value,
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</p>
|
2021-11-21 21:36:48 +00:00
|
|
|
</Field>
|
|
|
|
<Field name={t('http.kv-password')}>
|
|
|
|
<p className="control">
|
2021-05-02 12:29:43 +00:00
|
|
|
<input
|
2021-11-21 21:36:48 +00:00
|
|
|
className="input"
|
|
|
|
type="password"
|
2021-05-02 12:29:43 +00:00
|
|
|
disabled={busy}
|
2021-11-21 21:36:48 +00:00
|
|
|
placeholder="None"
|
|
|
|
value={httpConfig?.kv_password ?? ''}
|
2021-05-02 12:29:43 +00:00
|
|
|
onChange={(ev) =>
|
|
|
|
dispatch(
|
2021-11-19 18:46:48 +00:00
|
|
|
apiReducer.actions.httpConfigChanged({
|
|
|
|
...httpConfig,
|
2021-11-21 21:36:48 +00:00
|
|
|
kv_password: ev.target.value,
|
2021-05-02 12:29:43 +00:00
|
|
|
}),
|
|
|
|
)
|
|
|
|
}
|
2021-11-21 21:36:48 +00:00
|
|
|
/>
|
|
|
|
</p>
|
|
|
|
<p className="help">Leave empty to disable authentication</p>
|
|
|
|
</Field>
|
|
|
|
<Field name={t('http.static-content')}>
|
|
|
|
<label className="checkbox">
|
2021-05-02 12:29:43 +00:00
|
|
|
<input
|
2021-11-21 21:36:48 +00:00
|
|
|
type="checkbox"
|
|
|
|
disabled={busy}
|
|
|
|
checked={active}
|
2021-05-02 12:29:43 +00:00
|
|
|
onChange={(ev) =>
|
|
|
|
dispatch(
|
|
|
|
apiReducer.actions.httpConfigChanged({
|
|
|
|
...httpConfig,
|
2021-11-21 21:36:48 +00:00
|
|
|
enable_static_server: ev.target.checked,
|
2021-05-02 12:29:43 +00:00
|
|
|
}),
|
|
|
|
)
|
|
|
|
}
|
2021-11-21 21:36:48 +00:00
|
|
|
/>{' '}
|
|
|
|
{t('http.enable-static')}
|
|
|
|
</label>
|
|
|
|
</Field>
|
|
|
|
{active && (
|
|
|
|
<Field name={t('http.static-root-path')}>
|
|
|
|
<p className="control">
|
|
|
|
<input
|
|
|
|
className="input"
|
|
|
|
type="text"
|
|
|
|
disabled={busy || !active}
|
|
|
|
value={httpConfig?.path ?? ''}
|
|
|
|
onChange={(ev) =>
|
|
|
|
dispatch(
|
|
|
|
apiReducer.actions.httpConfigChanged({
|
|
|
|
...httpConfig,
|
|
|
|
path: ev.target.value,
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</p>
|
|
|
|
</Field>
|
|
|
|
)}
|
2021-05-02 12:29:43 +00:00
|
|
|
<button
|
|
|
|
className="button"
|
|
|
|
onClick={() => {
|
|
|
|
dispatch(setHTTPConfig(httpConfig));
|
2021-11-19 18:52:01 +00:00
|
|
|
const port = httpConfig.bind.split(':', 2)[1] ?? '4337';
|
|
|
|
if (port !== window.location.port) {
|
|
|
|
window.location.port = port;
|
|
|
|
}
|
2021-05-02 12:29:43 +00:00
|
|
|
}}
|
|
|
|
>
|
2021-09-17 09:55:15 +00:00
|
|
|
{t('actions.save')}
|
2021-05-02 12:29:43 +00:00
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|