1
0
Fork 0
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:
Ash Keel 2021-11-19 19:46:48 +01:00
parent 0d3233ecbd
commit 1be08573c5
No known key found for this signature in database
GPG key ID: BAD8D93E7314ED3E
4 changed files with 16 additions and 23 deletions

View file

@ -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;
} }

View file

@ -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}>

View file

@ -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));
}} }}
> >

View file

@ -15,14 +15,13 @@ import (
) )
type Server struct { type Server struct {
Config ServerConfig Config ServerConfig
db *database.DB db *database.DB
logger logrus.FieldLogger logger logrus.FieldLogger
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
} }
func NewServer(db *database.DB, log logrus.FieldLogger) (*Server, error) { func NewServer(db *database.DB, log logrus.FieldLogger) (*Server, error) {
@ -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