mirror of
https://git.sr.ht/~ashkeel/strimertul
synced 2024-09-20 02:00:49 +00:00
Fix new static server setting not working
This commit is contained in:
parent
0d3233ecbd
commit
1be08573c5
4 changed files with 16 additions and 23 deletions
|
@ -5,7 +5,6 @@ import KilovoltWS from '@strimertul/kilovolt-client';
|
||||||
interface ModuleConfig {
|
interface ModuleConfig {
|
||||||
configured: boolean;
|
configured: boolean;
|
||||||
kv: boolean;
|
kv: boolean;
|
||||||
static: boolean;
|
|
||||||
twitch: boolean;
|
twitch: boolean;
|
||||||
stulbe: boolean;
|
stulbe: boolean;
|
||||||
loyalty: boolean;
|
loyalty: boolean;
|
||||||
|
@ -13,6 +12,7 @@ interface ModuleConfig {
|
||||||
|
|
||||||
interface HTTPConfig {
|
interface HTTPConfig {
|
||||||
bind: string;
|
bind: string;
|
||||||
|
enable_static_server: boolean;
|
||||||
path: string;
|
path: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ export default function App(): React.ReactElement {
|
||||||
return <div className="container">{t('system.loading')}</div>;
|
return <div className="container">{t('system.loading')}</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const basepath = process.env.NODE_ENV === 'development' ? '/' : '/ui/';
|
const basepath = '/ui/';
|
||||||
|
|
||||||
const routeItem = ({ route, name, subroutes }: RouteItem) => (
|
const routeItem = ({ route, name, subroutes }: RouteItem) => (
|
||||||
<li key={route}>
|
<li key={route}>
|
||||||
|
|
|
@ -10,12 +10,11 @@ export default function HTTPPage(
|
||||||
params: RouteComponentProps<unknown>,
|
params: RouteComponentProps<unknown>,
|
||||||
): React.ReactElement {
|
): React.ReactElement {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [moduleConfig, setModuleConfig] = useModule(modules.moduleConfig);
|
|
||||||
const [httpConfig, setHTTPConfig] = useModule(modules.httpConfig);
|
const [httpConfig, setHTTPConfig] = useModule(modules.httpConfig);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
const busy = moduleConfig === null || httpConfig === null;
|
const busy = httpConfig === null;
|
||||||
const active = moduleConfig?.static ?? false;
|
const active = httpConfig?.enable_static_server ?? false;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -50,9 +49,9 @@ export default function HTTPPage(
|
||||||
checked={active}
|
checked={active}
|
||||||
onChange={(ev) =>
|
onChange={(ev) =>
|
||||||
dispatch(
|
dispatch(
|
||||||
apiReducer.actions.moduleConfigChanged({
|
apiReducer.actions.httpConfigChanged({
|
||||||
...moduleConfig,
|
...httpConfig,
|
||||||
static: ev.target.checked,
|
enable_static_server: ev.target.checked,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -82,7 +81,6 @@ export default function HTTPPage(
|
||||||
<button
|
<button
|
||||||
className="button"
|
className="button"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
dispatch(setModuleConfig(moduleConfig));
|
|
||||||
dispatch(setHTTPConfig(httpConfig));
|
dispatch(setHTTPConfig(httpConfig));
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
|
@ -21,7 +21,6 @@ type Server struct {
|
||||||
server *http.Server
|
server *http.Server
|
||||||
frontend fs.FS
|
frontend fs.FS
|
||||||
hub *kv.Hub
|
hub *kv.Hub
|
||||||
staticPath string
|
|
||||||
mux *http.ServeMux
|
mux *http.ServeMux
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,10 +47,6 @@ func (s *Server) SetHub(hub *kv.Hub) {
|
||||||
s.hub = hub
|
s.hub = hub
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) SetStaticPath(path string) {
|
|
||||||
s.staticPath = path
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) makeMux() *http.ServeMux {
|
func (s *Server) makeMux() *http.ServeMux {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
|
@ -63,8 +58,8 @@ func (s *Server) makeMux() *http.ServeMux {
|
||||||
kv.ServeWs(s.hub, w, r)
|
kv.ServeWs(s.hub, w, r)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if s.staticPath != "" {
|
if s.Config.EnableStaticServer {
|
||||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(s.staticPath))))
|
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(s.Config.Path))))
|
||||||
}
|
}
|
||||||
|
|
||||||
return mux
|
return mux
|
||||||
|
|
Loading…
Reference in a new issue